-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fc] Repository: plone.app.querystring
Branch: refs/heads/master Date: 2023-11-29T13:33:12+01:00 Author: Mikel Larreategi (erral) <[email protected]> Commit: plone/plone.app.querystring@c66c920 handle parenthesis inside quotes Files changed: A news/139.bugfix M plone/app/querystring/querybuilder.py M plone/app/querystring/tests/testQueryBuilder.py Repository: plone.app.querystring Branch: refs/heads/master Date: 2023-11-29T13:35:51+01:00 Author: Mikel Larreategi (erral) <[email protected]> Commit: plone/plone.app.querystring@5b2909f run black Files changed: M plone/app/querystring/tests/testQueryBuilder.py Repository: plone.app.querystring Branch: refs/heads/master Date: 2023-12-14T12:20:43+01:00 Author: Maurits van Rees (mauritsvanrees) <[email protected]> Commit: plone/plone.app.querystring@84d730b Merge pull request #140 from plone/erral-issue-139 handle parenthesis inside quotes Files changed: A news/139.bugfix M plone/app/querystring/querybuilder.py M plone/app/querystring/tests/testQueryBuilder.py
- Loading branch information
1 parent
a668c05
commit a5c836d
Showing
1 changed file
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,51 @@ | ||
Repository: Products.CMFPlone | ||
Repository: plone.app.querystring | ||
|
||
|
||
Branch: refs/heads/6.0.x | ||
Date: 2023-11-29T12:39:52+01:00 | ||
Branch: refs/heads/master | ||
Date: 2023-11-29T13:33:12+01:00 | ||
Author: Mikel Larreategi (erral) <[email protected]> | ||
Commit: https://github.com/plone/Products.CMFPlone/commit/9c2ec1e3a1490d9df2d6aaae74b1af3b4b525f60 | ||
Commit: https://github.com/plone/plone.app.querystring/commit/c66c920642887141ec6c9ac2fcf87f363d12de01 | ||
|
||
handle parenthesis inside quotes | ||
|
||
Files changed: | ||
A news/3879.bugfix | ||
M Products/CMFPlone/browser/search.py | ||
M Products/CMFPlone/tests/testSearch.py | ||
A news/139.bugfix | ||
M plone/app/querystring/querybuilder.py | ||
M plone/app/querystring/tests/testQueryBuilder.py | ||
|
||
b'diff --git a/Products/CMFPlone/browser/search.py b/Products/CMFPlone/browser/search.py\nindex 108a8f0b54..84503505dd 100644\n--- a/Products/CMFPlone/browser/search.py\n+++ b/Products/CMFPlone/browser/search.py\n@@ -45,10 +45,11 @@ def quote(term):\n # being parsed as logical query atoms.\n if term.lower() in ("and", "or", "not"):\n term = \'"%s"\' % term\n- return term\n+ return quote_chars(term)\n \n \n def munge_search_term(query):\n+ original_query = query\n for char in BAD_CHARS:\n query = query.replace(char, " ")\n \n@@ -67,7 +68,7 @@ def munge_search_term(query):\n \n r += map(quote, query.strip().split())\n r = " AND ".join(r)\n- r = quote_chars(r) + ("*" if r and not r.endswith(\'"\') else "")\n+ r = r + ("*" if r and not original_query.endswith(\'"\') else "")\n return r\n \n \ndiff --git a/Products/CMFPlone/tests/testSearch.py b/Products/CMFPlone/tests/testSearch.py\nindex 54b43d8861..e1d00b8567 100644\n--- a/Products/CMFPlone/tests/testSearch.py\n+++ b/Products/CMFPlone/tests/testSearch.py\n@@ -364,6 +364,21 @@ def test_munge_search_term(self):\n \'" spam ham "\',\n \'"spam ham"\',\n ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam (ham)"\',\n+ \'"spam (ham)"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam" (ham)\',\n+ \'"spam" AND "("ham")"*\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"(spam ham)"\',\n+ \'"(spam ham)"\',\n+ ),\n (\n # mixed cases\n "Spam hAm",\ndiff --git a/news/3879.bugfix b/news/3879.bugfix\nnew file mode 100644\nindex 0000000000..2b1cb9b691\n--- /dev/null\n+++ b/news/3879.bugfix\n@@ -0,0 +1,2 @@\n+Handle catalog queries with parenthesis inside quotes\n+[erral]\n' | ||
b'diff --git a/news/139.bugfix b/news/139.bugfix\nnew file mode 100644\nindex 0000000..ec4772e\n--- /dev/null\n+++ b/news/139.bugfix\n@@ -0,0 +1,2 @@\n+Handle parenthesis inside quotes\n+[erral]\ndiff --git a/plone/app/querystring/querybuilder.py b/plone/app/querystring/querybuilder.py\nindex d9ef15b..bd8978f 100644\n--- a/plone/app/querystring/querybuilder.py\n+++ b/plone/app/querystring/querybuilder.py\n@@ -44,10 +44,11 @@ def _quote(term):\n # being parsed as logical query atoms.\n if term.lower() in ("and", "or", "not"):\n term = \'"%s"\' % term\n- return term\n+ return _quote_chars(term)\n \n \n def munge_search_term(query):\n+ original_query = query\n for char in _BAD_CHARS:\n query = query.replace(char, " ")\n \n@@ -66,7 +67,7 @@ def munge_search_term(query):\n \n r += map(_quote, query.strip().split())\n r = " AND ".join(r)\n- r = _quote_chars(r) + ("*" if r and not r.endswith(\'"\') else "")\n+ r = r + ("*" if r and not original_query.endswith(\'"\') else "")\n return r\n \n \ndiff --git a/plone/app/querystring/tests/testQueryBuilder.py b/plone/app/querystring/tests/testQueryBuilder.py\nindex 4c39838..48b6e43 100644\n--- a/plone/app/querystring/tests/testQueryBuilder.py\n+++ b/plone/app/querystring/tests/testQueryBuilder.py\n@@ -326,6 +326,80 @@ def testQueryBuilderCustomQueryDoNotOverrideValues(self):\n self.assertEqual(results[0].Title(), "Collectionstestpage 2")\n \n \n+ def test_munge_search_term(self):\n+ from plone.app.querystring.querybuilder import _BAD_CHARS\n+ from plone.app.querystring.querybuilder import munge_search_term\n+\n+ search_term_tests = [\n+ (\n+ # search term\n+ "spam ham",\n+ "spam AND ham*",\n+ ),\n+ (\n+ # quoted term\n+ \'"spam ham"\',\n+ \'"spam ham"\',\n+ ),\n+ (\n+ # cleanup quoted terms\n+ \'" spam ham "\',\n+ \'"spam ham"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam (ham)"\',\n+ \'"spam (ham)"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam" (ham)\',\n+ \'"spam" AND "("ham")"*\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"(spam ham)"\',\n+ \'"(spam ham)"\',\n+ ),\n+ (\n+ # mixed cases\n+ "Spam hAm",\n+ "Spam AND hAm*",\n+ ),\n+ (\n+ # mix quoting and unquoted\n+ \'let\\\'s eat some "ham and eggs " without spam \',\n+ \'"ham and eggs" AND let\\\'s AND eat AND some \' "AND without AND spam*",\n+ ),\n+ (\n+ \'test "Welcome" to "Plone" retest\',\n+ \'"Welcome" AND "Plone" AND test AND to AND retest*\',\n+ ),\n+ (\n+ # parentheses\n+ "spam (ham)",\n+ \'spam AND "("ham")"*\',\n+ ),\n+ (\n+ # special keywords\n+ "spam or not ham and eggs",\n+ \'spam AND "or" AND "not" AND ham AND "and" AND eggs*\',\n+ ),\n+ (\n+ # bad characters\n+ " ".join(_BAD_CHARS),\n+ "",\n+ ),\n+ (\n+ # weird input\n+ \'test ""Welcome" to "Plone"" retest\',\n+ \'"to" AND test AND WelcomePlone AND retest*\',\n+ ),\n+ ]\n+\n+ for _in, _out in search_term_tests:\n+ self.assertEqual(munge_search_term(_in), _out)\n+\n class TestQuerybuilderResultTypes(unittest.TestCase):\n layer = TEST_PROFILE_PLONEAPPQUERYSTRING_INTEGRATION_TESTING\n \n' | ||
|
||
Repository: Products.CMFPlone | ||
Repository: plone.app.querystring | ||
|
||
|
||
Branch: refs/heads/6.0.x | ||
Date: 2023-12-14T12:19:38+01:00 | ||
Author: Maurits van Rees (mauritsvanrees) <[email protected]> | ||
Commit: https://github.com/plone/Products.CMFPlone/commit/a91b86bdbc20376d6ac7933b79209e90ada13af0 | ||
Branch: refs/heads/master | ||
Date: 2023-11-29T13:35:51+01:00 | ||
Author: Mikel Larreategi (erral) <[email protected]> | ||
Commit: https://github.com/plone/plone.app.querystring/commit/5b2909f448b6da18ddb5751acc6e2dffef4cbedd | ||
|
||
run black | ||
|
||
Files changed: | ||
M plone/app/querystring/tests/testQueryBuilder.py | ||
|
||
b'diff --git a/plone/app/querystring/tests/testQueryBuilder.py b/plone/app/querystring/tests/testQueryBuilder.py\nindex 48b6e43..6a79bf0 100644\n--- a/plone/app/querystring/tests/testQueryBuilder.py\n+++ b/plone/app/querystring/tests/testQueryBuilder.py\n@@ -325,7 +325,6 @@ def testQueryBuilderCustomQueryDoNotOverrideValues(self):\n self.assertEqual(len(results), 1)\n self.assertEqual(results[0].Title(), "Collectionstestpage 2")\n \n-\n def test_munge_search_term(self):\n from plone.app.querystring.querybuilder import _BAD_CHARS\n from plone.app.querystring.querybuilder import munge_search_term\n@@ -400,6 +399,7 @@ def test_munge_search_term(self):\n for _in, _out in search_term_tests:\n self.assertEqual(munge_search_term(_in), _out)\n \n+\n class TestQuerybuilderResultTypes(unittest.TestCase):\n layer = TEST_PROFILE_PLONEAPPQUERYSTRING_INTEGRATION_TESTING\n \n' | ||
|
||
Merge pull request #3880 from plone/erral-issue-3879 | ||
Repository: plone.app.querystring | ||
|
||
Handle parenthesis inside quotes | ||
|
||
Branch: refs/heads/master | ||
Date: 2023-12-14T12:20:43+01:00 | ||
Author: Maurits van Rees (mauritsvanrees) <[email protected]> | ||
Commit: https://github.com/plone/plone.app.querystring/commit/84d730b65b1260c7eec85efcc3ab23116c150a2e | ||
|
||
Merge pull request #140 from plone/erral-issue-139 | ||
|
||
handle parenthesis inside quotes | ||
|
||
Files changed: | ||
A news/3879.bugfix | ||
M Products/CMFPlone/browser/search.py | ||
M Products/CMFPlone/tests/testSearch.py | ||
A news/139.bugfix | ||
M plone/app/querystring/querybuilder.py | ||
M plone/app/querystring/tests/testQueryBuilder.py | ||
|
||
b'diff --git a/Products/CMFPlone/browser/search.py b/Products/CMFPlone/browser/search.py\nindex 108a8f0b54..84503505dd 100644\n--- a/Products/CMFPlone/browser/search.py\n+++ b/Products/CMFPlone/browser/search.py\n@@ -45,10 +45,11 @@ def quote(term):\n # being parsed as logical query atoms.\n if term.lower() in ("and", "or", "not"):\n term = \'"%s"\' % term\n- return term\n+ return quote_chars(term)\n \n \n def munge_search_term(query):\n+ original_query = query\n for char in BAD_CHARS:\n query = query.replace(char, " ")\n \n@@ -67,7 +68,7 @@ def munge_search_term(query):\n \n r += map(quote, query.strip().split())\n r = " AND ".join(r)\n- r = quote_chars(r) + ("*" if r and not r.endswith(\'"\') else "")\n+ r = r + ("*" if r and not original_query.endswith(\'"\') else "")\n return r\n \n \ndiff --git a/Products/CMFPlone/tests/testSearch.py b/Products/CMFPlone/tests/testSearch.py\nindex 54b43d8861..e1d00b8567 100644\n--- a/Products/CMFPlone/tests/testSearch.py\n+++ b/Products/CMFPlone/tests/testSearch.py\n@@ -364,6 +364,21 @@ def test_munge_search_term(self):\n \'" spam ham "\',\n \'"spam ham"\',\n ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam (ham)"\',\n+ \'"spam (ham)"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam" (ham)\',\n+ \'"spam" AND "("ham")"*\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"(spam ham)"\',\n+ \'"(spam ham)"\',\n+ ),\n (\n # mixed cases\n "Spam hAm",\ndiff --git a/news/3879.bugfix b/news/3879.bugfix\nnew file mode 100644\nindex 0000000000..2b1cb9b691\n--- /dev/null\n+++ b/news/3879.bugfix\n@@ -0,0 +1,2 @@\n+Handle catalog queries with parenthesis inside quotes\n+[erral]\n' | ||
b'diff --git a/news/139.bugfix b/news/139.bugfix\nnew file mode 100644\nindex 0000000..ec4772e\n--- /dev/null\n+++ b/news/139.bugfix\n@@ -0,0 +1,2 @@\n+Handle parenthesis inside quotes\n+[erral]\ndiff --git a/plone/app/querystring/querybuilder.py b/plone/app/querystring/querybuilder.py\nindex d9ef15b..bd8978f 100644\n--- a/plone/app/querystring/querybuilder.py\n+++ b/plone/app/querystring/querybuilder.py\n@@ -44,10 +44,11 @@ def _quote(term):\n # being parsed as logical query atoms.\n if term.lower() in ("and", "or", "not"):\n term = \'"%s"\' % term\n- return term\n+ return _quote_chars(term)\n \n \n def munge_search_term(query):\n+ original_query = query\n for char in _BAD_CHARS:\n query = query.replace(char, " ")\n \n@@ -66,7 +67,7 @@ def munge_search_term(query):\n \n r += map(_quote, query.strip().split())\n r = " AND ".join(r)\n- r = _quote_chars(r) + ("*" if r and not r.endswith(\'"\') else "")\n+ r = r + ("*" if r and not original_query.endswith(\'"\') else "")\n return r\n \n \ndiff --git a/plone/app/querystring/tests/testQueryBuilder.py b/plone/app/querystring/tests/testQueryBuilder.py\nindex 4c39838..6a79bf0 100644\n--- a/plone/app/querystring/tests/testQueryBuilder.py\n+++ b/plone/app/querystring/tests/testQueryBuilder.py\n@@ -325,6 +325,80 @@ def testQueryBuilderCustomQueryDoNotOverrideValues(self):\n self.assertEqual(len(results), 1)\n self.assertEqual(results[0].Title(), "Collectionstestpage 2")\n \n+ def test_munge_search_term(self):\n+ from plone.app.querystring.querybuilder import _BAD_CHARS\n+ from plone.app.querystring.querybuilder import munge_search_term\n+\n+ search_term_tests = [\n+ (\n+ # search term\n+ "spam ham",\n+ "spam AND ham*",\n+ ),\n+ (\n+ # quoted term\n+ \'"spam ham"\',\n+ \'"spam ham"\',\n+ ),\n+ (\n+ # cleanup quoted terms\n+ \'" spam ham "\',\n+ \'"spam ham"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam (ham)"\',\n+ \'"spam (ham)"\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"spam" (ham)\',\n+ \'"spam" AND "("ham")"*\',\n+ ),\n+ (\n+ # quoted term with inner parenthesis\n+ \'"(spam ham)"\',\n+ \'"(spam ham)"\',\n+ ),\n+ (\n+ # mixed cases\n+ "Spam hAm",\n+ "Spam AND hAm*",\n+ ),\n+ (\n+ # mix quoting and unquoted\n+ \'let\\\'s eat some "ham and eggs " without spam \',\n+ \'"ham and eggs" AND let\\\'s AND eat AND some \' "AND without AND spam*",\n+ ),\n+ (\n+ \'test "Welcome" to "Plone" retest\',\n+ \'"Welcome" AND "Plone" AND test AND to AND retest*\',\n+ ),\n+ (\n+ # parentheses\n+ "spam (ham)",\n+ \'spam AND "("ham")"*\',\n+ ),\n+ (\n+ # special keywords\n+ "spam or not ham and eggs",\n+ \'spam AND "or" AND "not" AND ham AND "and" AND eggs*\',\n+ ),\n+ (\n+ # bad characters\n+ " ".join(_BAD_CHARS),\n+ "",\n+ ),\n+ (\n+ # weird input\n+ \'test ""Welcome" to "Plone"" retest\',\n+ \'"to" AND test AND WelcomePlone AND retest*\',\n+ ),\n+ ]\n+\n+ for _in, _out in search_term_tests:\n+ self.assertEqual(munge_search_term(_in), _out)\n+\n \n class TestQuerybuilderResultTypes(unittest.TestCase):\n layer = TEST_PROFILE_PLONEAPPQUERYSTRING_INTEGRATION_TESTING\n' | ||
|