Skip to content

Commit

Permalink
expand solr query escape flow to include single quotes (#7931)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaydenTeoh authored Jun 22, 2023
1 parent fec5263 commit 48e47e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion openlibrary/solr/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ def fully_escape_query(query: str) -> str:
'x\\\\:\\\\[A TO Z\\\\}'
>>> fully_escape_query('foo AND bar')
'foo and bar'
>>> fully_escape_query("foo's bar")
"foo\\\\'s bar"
"""
escaped = query
# Escape special characters
escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,]', r'\\\g<0>', escaped)
escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,\']', r'\\\g<0>', escaped)
# Remove boolean operators by making them lowercase
escaped = re.sub(r'AND|OR|NOT', lambda _1: _1.group(0).lower(), escaped)
return escaped
Expand Down

0 comments on commit 48e47e5

Please sign in to comment.