[javascriptlint-commit] SF.net SVN: javascriptlint:[385] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2018-06-10 20:42:01
|
Revision: 385 http://sourceforge.net/p/javascriptlint/code/385 Author: matthiasmiller Date: 2018-06-10 20:41:58 +0000 (Sun, 10 Jun 2018) Log Message: ----------- Respect escaping within regular expressions. Modified Paths: -------------- trunk/jsengine/parser/__init__.py trunk/jsengine/tokenizer/__init__.py trunk/tests/warnings/misplaced_regex.js Modified: trunk/jsengine/parser/__init__.py =================================================================== --- trunk/jsengine/parser/__init__.py 2018-06-10 20:26:59 UTC (rev 384) +++ trunk/jsengine/parser/__init__.py 2018-06-10 20:41:58 UTC (rev 385) @@ -853,6 +853,15 @@ self.assertEqual(error.offset, 5) else: self.assert_(False) + try: + # Do not allow after an escape sequence, either. + parsestring('re = /[\\\n'); + except JSSyntaxError as error: + self.assertEqual(error.offset, 5) + else: + self.assert_(False) + def testRegExpBugReport(self): + parsestring('validity = /[^\[\]/]/g') def testUnterminatedComment(self): try: parsestring('/*') Modified: trunk/jsengine/tokenizer/__init__.py =================================================================== --- trunk/jsengine/tokenizer/__init__.py 2018-06-10 20:26:59 UTC (rev 384) +++ trunk/jsengine/tokenizer/__init__.py 2018-06-10 20:41:58 UTC (rev 385) @@ -215,10 +215,16 @@ return Token(tok.ERROR) elif c == _Char.ord('['): while True: + # Handle escaped characters, but don't allow line breaks after the escape. c = stream.readchr() + escaped = False + if c == _Char.ord('\\'): + c = stream.readchr() + escaped = True + if c == _Char.ord('\n'): return Token(tok.ERROR) - elif c == _Char.ord(']'): + elif c == _Char.ord(']') and not escaped: break elif c == _Char.ord('\n'): return Token(tok.ERROR) Modified: trunk/tests/warnings/misplaced_regex.js =================================================================== --- trunk/tests/warnings/misplaced_regex.js 2018-06-10 20:26:59 UTC (rev 384) +++ trunk/tests/warnings/misplaced_regex.js 2018-06-10 20:41:58 UTC (rev 385) @@ -21,6 +21,9 @@ i += /\/\./; /*warning:misplaced_regex*/ i = -/.*/; /*warning:misplaced_regex*/ + /* legal usage */ + var validity = /[^\[\]/]/g; + /* legal usage: return */ return /\/\./; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |