diff options
| -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"-") | 
