Skip to content

Commit 48e47e5

Browse files
authored
expand solr query escape flow to include single quotes (#7931)
1 parent fec5263 commit 48e47e5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

openlibrary/solr/query_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ def fully_escape_query(query: str) -> str:
131131
'x\\\\:\\\\[A TO Z\\\\}'
132132
>>> fully_escape_query('foo AND bar')
133133
'foo and bar'
134+
>>> fully_escape_query("foo's bar")
135+
"foo\\\\'s bar"
134136
"""
135137
escaped = query
136138
# Escape special characters
137-
escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,]', r'\\\g<0>', escaped)
139+
escaped = re.sub(r'[\[\]\(\)\{\}:"\-+?~^/\\,\']', r'\\\g<0>', escaped)
138140
# Remove boolean operators by making them lowercase
139141
escaped = re.sub(r'AND|OR|NOT', lambda _1: _1.group(0).lower(), escaped)
140142
return escaped

0 commit comments

Comments
 (0)