Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Escape user-provided text passed to regex
Browse files Browse the repository at this point in the history
Rather than using the user/document-provided values directly, we instead
escape them to use them verbatim.

This fixes issue #568.
  • Loading branch information
pitkley committed Feb 23, 2020
1 parent e0da952 commit 3e6d177
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ def _split_match(self):
==>
["some", "random", "words", "with+quotes", "and", "spaces"]
"""
# We are escaping the match provided, although we unescape spaces again
# to not break the existing splitting logic.
match = re.escape(self.match).replace("\\ ", " ")

findterms = re.compile(r'"([^"]+)"|(\S+)').findall
normspace = re.compile(r"\s+").sub
return [
normspace(" ", (t[0] or t[1]).strip()).replace(" ", r"\s+")
for t in findterms(self.match)
for t in findterms(match)
]

def save(self, *args, **kwargs):
Expand Down

0 comments on commit 3e6d177

Please sign in to comment.