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

Commit 3e6d177

Browse files
committed
Escape user-provided text passed to regex
Rather than using the user/document-provided values directly, we instead escape them to use them verbatim. This fixes issue #568.
1 parent e0da952 commit 3e6d177

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/documents/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ def _split_match(self):
138138
==>
139139
["some", "random", "words", "with+quotes", "and", "spaces"]
140140
"""
141+
# We are escaping the match provided, although we unescape spaces again
142+
# to not break the existing splitting logic.
143+
match = re.escape(self.match).replace("\\ ", " ")
144+
141145
findterms = re.compile(r'"([^"]+)"|(\S+)').findall
142146
normspace = re.compile(r"\s+").sub
143147
return [
144148
normspace(" ", (t[0] or t[1]).strip()).replace(" ", r"\s+")
145-
for t in findterms(self.match)
149+
for t in findterms(match)
146150
]
147151

148152
def save(self, *args, **kwargs):

0 commit comments

Comments
 (0)