diff --git a/server/szurubooru/search/parser.py b/server/szurubooru/search/parser.py index 4cde70b..f610b3b 100644 --- a/server/szurubooru/search/parser.py +++ b/server/szurubooru/search/parser.py @@ -4,14 +4,14 @@ from szurubooru.search import criteria, tokens def _create_criterion(original_value, value): + if ',' in value: + return criteria.ArrayCriterion( + original_value, value.split(',')) if '..' in value: low, high = value.split('..', 1) if not low and not high: raise errors.SearchError('Empty ranged value') return criteria.RangedCriterion(original_value, low, high) - if ',' in value: - return criteria.ArrayCriterion( - original_value, value.split(',')) return criteria.PlainCriterion(original_value, value) diff --git a/server/szurubooru/tests/search/configs/test_user_search_config.py b/server/szurubooru/tests/search/configs/test_user_search_config.py index ae182fd..37e641a 100644 --- a/server/szurubooru/tests/search/configs/test_user_search_config.py +++ b/server/szurubooru/tests/search/configs/test_user_search_config.py @@ -84,6 +84,23 @@ def test_filter_by_name( verify_unpaged(input, expected_user_names) +@pytest.mark.parametrize('input,expected_user_names', [ + ('name:u1', ['u1']), + ('name:u2..', ['u2..']), + ('name:u2*', ['u2..']), + ('name:*..*', ['u2..', 'u3..x']), + ('name:u3..x', ['u3..x']), + ('name:*..x', ['u3..x']), + ('name:u1,u3..x', ['u1', 'u3..x']), +]) +def test_filter_by_name_that_looks_like_range( + verify_unpaged, input, expected_user_names, user_factory): + db.session.add(user_factory(name='u1')) + db.session.add(user_factory(name='u2..')) + db.session.add(user_factory(name='u3..x')) + db.session.flush() + verify_unpaged(input, expected_user_names) + @pytest.mark.parametrize('input,expected_user_names', [ ('', ['u1', 'u2']), ('u1', ['u1']), @@ -224,7 +241,6 @@ def test_random_sort(executor, user_factory): ('creation-date:bad..', errors.ValidationError), ('creation-date:..bad', errors.ValidationError), ('creation-date:bad..bad', errors.ValidationError), - ('name:a..b', errors.SearchError), ('sort:', errors.SearchError), ('sort:nam', errors.SearchError), ('sort:name,as', errors.SearchError),