You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repl hates comments with quotes in indented code #3421
$ node
> function foo() {
... //'
SyntaxError: Unexpected end of input
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:137:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
>
I played around with this code today and found there are two other scenarios where we can get this same error.
$ node
> function foo() { //'
SyntaxError: Unexpected end of input
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:137:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
The other scenario:
$ node
> function foo() {
... var i = "'";
SyntaxError: Unexpected end of input
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:137:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
After reviewing the repl code, I think I have a fix. I've included repl's parseLine function with my annotated changes below. Is this ready for a pull request @thefourtheye ?
function parseLine(line, currentStringLiteral) {
var previous = null, current = null;
for (var i = 0; i < line.length; i += 1) {
if (previous === '\\') {
// if it is a valid escaping, then skip processing and the previous
// character doesn't matter anymore.
previous = null;
continue;
}
current = line.charAt(i);
// Issue 3421: If a comment is detected and there is no string
// literal, then it's safe to stop parsing the rest of the line
if (previous === '/' && current === '/' &&
currentStringLiteral === null) {
break;
} else if (current === currentStringLiteral) {
currentStringLiteral = null;
}
// Issue 3421: Operator precedence caused a double quote string to fail
// when a single quote was inside the double quote string.
else if ((current === '\'' ||
current === '"') &&
currentStringLiteral === null) {
currentStringLiteral = current;
}
previous = current;
}
return currentStringLiteral;
}
@ChuckLangford I think it's going to be more complicated than that? For example, this fails also, but with a different exception:
> function foo(){
... /*'
SyntaxError: Unexpected token ILLEGAL
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:137:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:393:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
>
@ChuckLangford Yes, what @mscdex said is true. I am working on a fix with a little of bit of refactoring as well. I think I'll send a PR today or tomorrow.
As a coding exercise, I'm going to continue working on this problem. @mscdex@thefourtheye have either of you found any other examples of comment related code that will crash repl?
Activity
ChuckLangford commentedon Oct 18, 2015
I played around with this code today and found there are two other scenarios where we can get this same error.
The other scenario:
silverwind commentedon Oct 19, 2015
cc @thefourtheye
ChuckLangford commentedon Oct 22, 2015
After reviewing the repl code, I think I have a fix. I've included repl's parseLine function with my annotated changes below. Is this ready for a pull request @thefourtheye ?
mscdex commentedon Oct 22, 2015
@ChuckLangford I think it's going to be more complicated than that? For example, this fails also, but with a different exception:
thefourtheye commentedon Oct 22, 2015
@ChuckLangford Yes, what @mscdex said is true. I am working on a fix with a little of bit of refactoring as well. I think I'll send a PR today or tomorrow.
ChuckLangford commentedon Oct 22, 2015
Awesome. Thanks for the feedback.
As a coding exercise, I'm going to continue working on this problem. @mscdex @thefourtheye have either of you found any other examples of comment related code that will crash repl?
mscdex commentedon Oct 22, 2015
@ChuckLangford I haven't had time to do any exhaustive testing yet, so it's possible there may be some other cases lurking...
thefourtheye commentedon Oct 25, 2015
PTAL at the proposed fix #3515
repl: handle comments properly
repl: handle comments properly
repl: handle comments properly
repl: handle comments properly