diff --git a/swh/graphql/resolvers/directory_entry.py b/swh/graphql/resolvers/directory_entry.py --- a/swh/graphql/resolvers/directory_entry.py +++ b/swh/graphql/resolvers/directory_entry.py @@ -56,6 +56,8 @@ if name_include is not None: # STORAGE-TODO, move this filter to swh-storage entries = [ - x for x in entries if name_include.lower().encode() in x.name.lower() + x + for x in entries + if name_include.casefold() in x.name.decode().casefold() ] return utils.paginated(entries, self._get_first_arg(), self._get_after_arg()) diff --git a/swh/graphql/tests/data.py b/swh/graphql/tests/data.py --- a/swh/graphql/tests/data.py +++ b/swh/graphql/tests/data.py @@ -127,6 +127,21 @@ ] +def get_directories_with_special_name_entries(): + return [ + Directory( + entries=( + DirectoryEntry( + name="ßßétEÉt".encode(), + perms=0o644, + type="file", + target=get_contents()[0].sha1_git, + ), + ) + ) + ] + + def get_visit_with_multiple_status(): return [ OriginVisitStatus( @@ -144,7 +159,8 @@ GRAPHQL_EXTRA_TEST_OBJECTS = { "release": get_releases_with_target(), "revision": get_revisions_with_parents(), - "directory": get_directories_with_nested_path(), + "directory": get_directories_with_nested_path() + + get_directories_with_special_name_entries(), "origin_visit_status": get_visit_with_multiple_status(), } diff --git a/swh/graphql/tests/functional/test_directory_entry.py b/swh/graphql/tests/functional/test_directory_entry.py --- a/swh/graphql/tests/functional/test_directory_entry.py +++ b/swh/graphql/tests/functional/test_directory_entry.py @@ -9,7 +9,11 @@ from swh.model.swhids import CoreSWHID, ObjectType from . import utils -from ..data import get_directories, get_directories_with_nested_path +from ..data import ( + get_directories, + get_directories_with_nested_path, + get_directories_with_special_name_entries, +) def get_target_type(target_type): @@ -154,3 +158,31 @@ for entry in data["directory"]["entries"]["nodes"]: assert name_include in entry["name"]["text"] assert entry["targetType"] == get_target_type(dir_entry["type"]) + + +def test_directory_entry_connection_filter_by_name_special_chars(client): + directory = get_directories_with_special_name_entries()[0] + query_str = """ + query getDirectory($swhid: SWHID!, $nameInclude: String) { + directory(swhid: $swhid) { + entries(nameInclude: $nameInclude) { + nodes { + targetType + name { + text + } + } + } + } + } + """ + data, _ = utils.get_query_response( + client, + query_str, + swhid=str(directory.swhid()), + nameInclude="ssSSé", + ) + assert data["directory"]["entries"]["nodes"][0] == { + "name": {"text": "ßßétEÉt"}, + "targetType": "content", + }