Merge pull request #36 from vwyu/master

Escape literal special characters in sre_to_string method.
This commit is contained in:
Adam Tauber 2019-01-14 13:22:49 +01:00 committed by GitHub
commit 6973340904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -306,7 +306,8 @@ def sre_to_string(sre_obj, paren=True):
prefix = '^'
ret += u'[{0}{1}]'.format(prefix, sre_to_string(i[1], paren=paren))
elif i[0] == sre_parse.LITERAL:
ret += unichr(i[1])
u = unichr(i[1])
ret += u if u not in sre_parse.SPECIAL_CHARS else '\\{0}'.format(u)
elif i[0] == sre_parse.CATEGORY:
ret += REVERSE_CATEGORIES[i[1]]
elif i[0] == sre_parse.ANY: