Permalink
Browse files

Regular expression can not have LineTerminator.

  • Loading branch information...
1 parent 40dc5f2 commit 81f2703006f635d906d4cf18ffd5812c64e428fb @ariya committed Oct 1, 2013
Showing with 16 additions and 2 deletions.
  1. +2 −2 esprima.js
  2. +14 −0 test/test.js
View
4 esprima.js
@@ -1055,6 +1055,8 @@ parseStatement: true, parseSourceElement: true */
throwError({}, Messages.UnterminatedRegExp);
}
str += ch;
+ } else if (isLineTerminator(ch.charCodeAt(0))) {
+ throwError({}, Messages.UnterminatedRegExp);
} else if (classMarker) {
if (ch === ']') {
classMarker = false;
@@ -1065,8 +1067,6 @@ parseStatement: true, parseSourceElement: true */
break;
} else if (ch === '[') {
classMarker = true;
- } else if (isLineTerminator(ch.charCodeAt(0))) {
- throwError({}, Messages.UnterminatedRegExp);
}
}
}
View
14 test/test.js
@@ -17733,13 +17733,27 @@ var testFixture = {
message: 'Error: Line 1: Invalid regular expression: missing /'
},
+ '/test\n/': {
+ index: 6,
+ lineNumber: 1,
+ column: 7,
+ message: 'Error: Line 1: Invalid regular expression: missing /'
+ },
+
'var x = /[a-z]/\\ux': {
index: 18,
lineNumber: 1,
column: 19,
message: 'Error: Line 1: Invalid regular expression'
},
+ 'var x = /[a-z\n]/\\ux': {
+ index: 14,
+ lineNumber: 1,
+ column: 15,
+ message: 'Error: Line 1: Invalid regular expression: missing /'
+ },
+
'3 = 4': {
index: 1,
lineNumber: 1,

0 comments on commit 81f2703

Please sign in to comment.