From 48e47e579a20e33685de70bf404521e0cd62e54c Mon Sep 17 00:00:00 2001 From: Jayden Teoh <90945854+JaydenTeoh@users.noreply.github.com> Date: Fri, 23 Jun 2023 01:13:08 +0800 Subject: [PATCH] expand solr query escape flow to include single quotes (#7931) --- openlibrary/solr/query_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openlibrary/solr/query_utils.py b/openlibrary/solr/query_utils.py index 116733bb4cc..82d40d9cede 100644 --- a/openlibrary/solr/query_utils.py +++ b/openlibrary/solr/query_utils.py @@ -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