diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-21 12:32:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:41:37 +0200 |
commit | 97ca6b195c509635a71a1bd1d15c0f24592e714d (patch) | |
tree | d64cf19a3cf5869db8773e5b8805cc67ca51e390 | |
parent | 426e963e1504fd6d80c0f34af31dfbeb95ec2ae3 (diff) | |
download | Ishtar-97ca6b195c509635a71a1bd1d15c0f24592e714d.tar.bz2 Ishtar-97ca6b195c509635a71a1bd1d15c0f24592e714d.zip |
Facet search: manage term containing = or | inside quotes
-rw-r--r-- | archaeological_operations/tests.py | 13 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index b983ff6de..6781cf531 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1670,6 +1670,8 @@ class OperationSearchTest(TestCase, OperationInitTest): response = c.get(reverse('get-operation'), search) self.assertEqual(response.status_code, 200) result = json.loads(response.content) + if not result: + result = {"recordsTotal": 0} self.assertEqual(result['recordsTotal'], number, u"{} - {} - {} result(s) expected got {}".format( name, q, number, result['recordsTotal'])) @@ -1785,6 +1787,17 @@ class OperationSearchTest(TestCase, OperationInitTest): response = c.get(reverse('get-operation'), search) self.assertEqual(json.loads(response.content)['recordsTotal'], 2) + def test_search_with_problematic_characters(self): + c = Client() + c.login(username=self.username, password=self.password) + ope = self.operations[0] + lbl = "aha = take on me | take me on" + ope.common_name = lbl + ope.save() + search_name_q = str(pgettext("key for text search", u"name")) + self._test_search(c, search_name_q, lbl, 1, + "Facet search with = and | characters") + def test_hierarchic_search(self): ope = self.operations[1] c = Client() diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 16128feba..ca75bffe1 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -390,14 +390,19 @@ def _parse_parentheses(s): FORBIDDEN_CHAR = [u":"] RESERVED_CHAR = [u"|", u"&"] +RE_FACET = re.compile('([-a-zA-Z]+)="([^"]+)"') def _parse_query_string(string, query_parameters, current_dct, exc_dct, extra_distinct_q): string = string.strip().lower() - if u"=" in string: - splited = string.split(u"=") + match = RE_FACET.search(string) + if match or u"=" in string: + if match: + splited = match.groups() + else: + splited = string.split(u"=") if len(splited) == 2: base_term, query = splited excluded = base_term.startswith(u"-") |