Skip to content

Commit

Permalink
add tests for searching with parantheses
Browse files Browse the repository at this point in the history
  • Loading branch information
tedw87 committed Oct 30, 2024
1 parent cd717ef commit 1375bea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/plone/restapi/search/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _constrain_query_by_path(self, query):

def quote_chars(self, query):
# Remove parentheses from the query
return query.replace("(", "").replace(")", "").strip()
return query.replace("(", " ").replace(")", " ").strip()

def search(self, query=None):
if query is None:
Expand Down Expand Up @@ -110,7 +110,6 @@ def search(self, query=None):
results = getMultiAdapter((lazy_resultset, self.request), ISerializeToJson)(
fullobjects=fullobjects
)

return results

def filter_types(self, types):
Expand Down
17 changes: 17 additions & 0 deletions src/plone/restapi/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ def test_search_on_context_constrains_query_by_path(self):
set(result_paths(response.json())),
)

def test_search_with_parentheses(self):
query = {"SearchableText": "("}
response = self.api_session.get("/@search", params=query)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [], "Expected no items for query with only parentheses")

query = {"SearchableText": ")"}
response = self.api_session.get("/@search", params=query)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), [], "Expected no items for query with only parentheses")

query = {"SearchableText": "lorem(ipsum)"}
response = self.api_session.get("/@search", params=query)
self.assertEqual(response.status_code, 200)
items = [item["title"] for item in response.json().get("items", [])]
self.assertIn("Lorem Ipsum", items, "Expected 'Lorem Ipsum' to be found in search results")

def test_search_in_vhm(self):
# Install a Virtual Host Monster
if "virtual_hosting" not in self.app.objectIds():
Expand Down

0 comments on commit 1375bea

Please sign in to comment.