Skip to content

Commit

Permalink
NOREF Escape forward slash in queries
Browse files Browse the repository at this point in the history
There was a single character not being escaped that is a Lucene special character - forward slash. This caused a very small subset of queries to fail and this adds it to the escaped character regex to prevent this from happening in the future.
  • Loading branch information
mwbenowitz committed Jun 30, 2021
1 parent 486f3b4 commit 616510e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def makeDictHashable(cls, object):

@staticmethod
def escapeSearchQuery(query):
return re.sub(r'[\+\-\&\|\!\(\)\[\]\{\}\^\~\?\:\\]{1}', '\\\\\g<0>', query)
return re.sub(r'[\+\-\&\|\!\(\)\[\]\{\}\^\~\?\:\\\/]{1}', '\\\\\g<0>', query)

def languageQuery(self, workTotals):
search = self.createSearch()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_api_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def test_makeDictHashable(self, mocker):
)

def test_escapeSearchQuery_changed(self):
assert ElasticClient.escapeSearchQuery('[test]+a:thing!') == '\[test\]\+a\:thing\!'
assert ElasticClient.escapeSearchQuery('/[test]+a:thing!') == '\/\[test\]\+a\:thing\!'

def test_escapeSearchQuery_unchanged(self):
assert ElasticClient.escapeSearchQuery('a simple query') == 'a simple query'
Expand Down

0 comments on commit 616510e

Please sign in to comment.