Skip to content

Commit

Permalink
Adjust string literal parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Jan 30, 2025
1 parent 37a50f1 commit 353585b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rule_engine/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#

import ast as pyast
import codecs
import collections
import types as pytypes

Expand Down Expand Up @@ -452,9 +453,12 @@ def p_expression_set(self, p):

def p_expression_string(self, p):
'object : STRING'
value = p[1][1:-1]
try:
value = p[1][1:-1].encode().decode('unicode-escape')
except Exception:
value = codecs.encode(value, 'unicode-escape').decode()
value = value.replace('\\\\', '\\')
value = codecs.decode(value, 'unicode-escape')
except UnicodeError:
raise errors.StringSyntaxError('invalid string literal', p[1][1:-1]) from None
p[0] = _DeferredAstNode(ast.StringExpression, args=(self.context, value))

Expand Down

0 comments on commit 353585b

Please sign in to comment.