Skip to content

Commit 353585b

Browse files
committed
Adjust string literal parsing
1 parent 37a50f1 commit 353585b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/rule_engine/parser/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#
3232

3333
import ast as pyast
34+
import codecs
3435
import collections
3536
import types as pytypes
3637

@@ -452,9 +453,12 @@ def p_expression_set(self, p):
452453

453454
def p_expression_string(self, p):
454455
'object : STRING'
456+
value = p[1][1:-1]
455457
try:
456-
value = p[1][1:-1].encode().decode('unicode-escape')
457-
except Exception:
458+
value = codecs.encode(value, 'unicode-escape').decode()
459+
value = value.replace('\\\\', '\\')
460+
value = codecs.decode(value, 'unicode-escape')
461+
except UnicodeError:
458462
raise errors.StringSyntaxError('invalid string literal', p[1][1:-1]) from None
459463
p[0] = _DeferredAstNode(ast.StringExpression, args=(self.context, value))
460464

0 commit comments

Comments
 (0)