Skip to content

Commit 101e103

Browse files
author
Julien Gilli
committed
repl: make 'Unexpected token' errors recoverable
Fix the regexp used to detect 'Unexpected token' errors so that they can be considered as recoverable. This fixes the following use case: > var foo = 'bar \ ... baz'; undefined > foo 'bar baz' > Fixes #8874 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> PR-URL: nodejs/node-v0.x-archive#8875
1 parent 0dbaee4 commit 101e103

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ REPLServer.prototype.convertToContext = function(cmd) {
949949
function isRecoverableError(e) {
950950
return e &&
951951
e.name === 'SyntaxError' &&
952-
/^(Unexpected end of input|Unexpected token :)/.test(e.message);
952+
/^(Unexpected end of input|Unexpected token)/.test(e.message);
953953
}
954954

955955
function Recoverable(err) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
/*
23+
* This is a regression test for https://github.com/joyent/node/issues/8874.
24+
*/
25+
var common = require('../common');
26+
var assert = require('assert');
27+
28+
var spawn = require('child_process').spawn;
29+
// use -i to force node into interactive mode, despite stdout not being a TTY
30+
var args = [ '-i' ];
31+
var child = spawn(process.execPath, args);
32+
33+
var input = 'var foo = "bar\\\nbaz"';
34+
// Match '...' as well since it marks a multi-line statement
35+
var expectOut = /^> ... undefined\n/;
36+
37+
child.stderr.setEncoding('utf8');
38+
child.stderr.on('data', function(c) {
39+
throw new Error('child.stderr be silent');
40+
});
41+
42+
child.stdout.setEncoding('utf8');
43+
var out = '';
44+
child.stdout.on('data', function(c) {
45+
out += c;
46+
});
47+
48+
child.stdout.on('end', function() {
49+
assert(expectOut.test(out));
50+
console.log('ok');
51+
});
52+
53+
child.stdin.end(input);

0 commit comments

Comments
 (0)