JSVar: oops

This commit is contained in:
smurail 2014-09-18 11:51:40 +02:00 committed by Romain Bignon
commit 99e797410d

View file

@ -28,7 +28,7 @@ __all__ = ['JSPayload', 'JSVar']
def _quoted(q): def _quoted(q):
return r'{0}(?:[^{0}]|\{0})*{0}'.format(q) return r'(?<!\\){0}(?:\\{0}|[^{0}])*{0}'.format(q)
class JSPayload(Filter): class JSPayload(Filter):
@ -68,13 +68,15 @@ class JSVar(Regexp):
It only understands literal values, but should parse them well. Values It only understands literal values, but should parse them well. Values
are converted in python values, quotes and slashes in strings are stripped. are converted in python values, quotes and slashes in strings are stripped.
>>> JSVar(var='test').filter("var test = .1") >>> JSVar(var='test').filter("var test = .1;\nsomecode()")
0.1 0.1
>>> JSVar(var='test').filter("test = 42") >>> JSVar(var='test').filter("test = 42;\nsomecode()")
42 42
>>> JSVar(var='test').filter('test = "Some \\"string\\" value"') >>> JSVar(var='test').filter("test = 'Some \\'string\\' value, isn\\'t it ?';\nsomecode()")
"Some 'string' value, isn't it ?"
>>> JSVar(var='test').filter('test = "Some \\"string\\" value";\nsomecode()')
'Some "string" value' 'Some "string" value'
>>> JSVar(var='test').filter("var test = false") >>> JSVar(var='test').filter("var test = false;\nsomecode()")
False False
""" """
pattern_template = r"""(?x) pattern_template = r"""(?x)