Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust string literal parsing
Browse files Browse the repository at this point in the history
zeroSteiner committed Jan 30, 2025
1 parent 721e9b6 commit 796c1e1
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
@@ -31,6 +31,7 @@
#

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

@@ -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))

0 comments on commit 796c1e1

Please sign in to comment.