浏览代码

Fix parsing of queries with multiple filters that contain quotes

bbeniamin 2 年之前
父节点
当前提交
96b94d01d9
共有 5 个文件被更改,包括 12 次插入1 次删除
  1. 1 0
      CHANGELOG.txt
  2. 1 0
      CONTRIBUTORS.rst
  3. 1 0
      docs/releases/4.2.md
  4. 8 0
      wagtail/search/tests/test_queries.py
  5. 1 1
      wagtail/search/utils.py

+ 1 - 0
CHANGELOG.txt

@@ -69,6 +69,7 @@ Changelog
  * Fix: Use the correct color for placeholders in rich text fields (Thibaud Colas)
  * Fix: Prevent obstructing the outline around rich text fields (Thibaud Colas)
  * Fix: Page editor dropdowns now use indigo backgrounds like elsewhere in the admin interface (Thibaud Colas)
+ * Fix: Allow parsing of multiple key/value pairs from string in `wagtail.search.utils.parse_query_string` (Beniamin Bucur)
  * Docs: Add custom permissions section to permissions documentation page (Dan Hayden)
  * Docs: Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare)
  * Docs: Officially recommend `fnm` over `nvm` in development documentation (LB (Ben) Johnston)

+ 1 - 0
CONTRIBUTORS.rst

@@ -683,6 +683,7 @@ Contributors
 * Alex Simpson
 * GLEF1X
 * Nick Lee
+* Beniamin Bucur
 
 Translators
 ===========

+ 1 - 0
docs/releases/4.2.md

@@ -106,6 +106,7 @@ This feature was developed by Matt Westcott, and sponsored by [YouGov](https://y
  * Use the correct color for placeholders in rich text fields (Thibaud Colas)
  * Prevent obstructing the outline around rich text fields (Thibaud Colas)
  * Page editor dropdowns now use indigo backgrounds like elsewhere in the admin interface (Thibaud Colas)
+ * Allow parsing of multiple key/value pairs from string in `wagtail.search.utils.parse_query_string` (Beniamin Bucur)
 
 ### Documentation
 

+ 8 - 0
wagtail/search/tests/test_queries.py

@@ -248,6 +248,14 @@ class TestSeparateFiltersFromQuery(SimpleTestCase):
         self.assertDictEqual(filters, {"author": "foo bar", "bar": "beer"})
         self.assertEqual(query, "hello world")
 
+    def test_two_filters_with_quotation_marks_and_query(self):
+        filters, query = separate_filters_from_query(
+            'author:"foo bar" hello world bar:"two beers"'
+        )
+
+        self.assertDictEqual(filters, {"author": "foo bar", "bar": "two beers"})
+        self.assertEqual(query, "hello world")
+
 
 class TestParseQueryString(SimpleTestCase):
     def test_simple_query(self):

+ 1 - 1
wagtail/search/utils.py

@@ -82,7 +82,7 @@ def normalise_query_string(query_string):
 
 
 def separate_filters_from_query(query_string):
-    filters_regexp = r'(\w+):(\w+|".+")'
+    filters_regexp = r'(\w+):(\w+|"[^"]+")'
 
     filters = {}
     for match_object in re.finditer(filters_regexp, query_string):