fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
aafd994
)
don't escape non-ascii for regular expressions
author
Jan Szejko
<jan.szejko@gmail.com>
Mon, 11 Jul 2016 16:21:07 +0000
(18:21 +0200)
committer
Jan Szejko
<jan.szejko@gmail.com>
Mon, 11 Jul 2016 16:21:07 +0000
(18:21 +0200)
src/catalogue/views.py
patch
|
blob
|
history
diff --git
a/src/catalogue/views.py
b/src/catalogue/views.py
index
6782e53
..
44a17b4
100644
(file)
--- a/
src/catalogue/views.py
+++ b/
src/catalogue/views.py
@@
-365,7
+365,14
@@
def _no_diacritics_regexp(query):
def unicode_re_escape(query):
""" Unicode-friendly version of re.escape """
- return re.sub(r'(?u)(\W)', r'\\\1', query)
+ s = list(query)
+ for i, c in enumerate(query):
+ if re.match(r'(?u)(\W)', c) and re.match(r'[\x00-\x7e]', c):
+ if c == "\000":
+ s[i] = "\\000"
+ else:
+ s[i] = "\\" + c
+ return query[:0].join(s)
def _word_starts_with(name, prefix):