Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb971cc

Browse filesBrowse files
thefourtheyervagg
authored andcommitted
repl: backslash bug fix
The actual problem was with the line parsing logic for string literals. When we use backslash in the string literals, it used to remember the `\` as the previous character even after we parsed the character next to it. This leads to REPL thinking that the end of string literals is not reached. This patch replaces the previous character with `null`, so that it will properly skip the character next to it. Previous Discussion: #2952 Fixes: #2749 PR-URL: #2968 Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent b93ad5a commit cb971cc
Copy full SHA for cb971cc

File tree

Expand file treeCollapse file tree

2 files changed

+10
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-2
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,9 @@ function REPLServer(prompt,
288288

289289
for (var i = 0; i < line.length; i += 1) {
290290
if (previous === '\\') {
291-
// if it is a valid escaping, then skip processing
292-
previous = current;
291+
// if it is a valid escaping, then skip processing and the previous
292+
// character doesn't matter anymore.
293+
previous = null;
293294
continue;
294295
}
295296

Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ function error_test() {
242242
'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n',
243243
expect: ['\'1\'\n', '\'2\'\n', '\'3\'\n', '\'4\'\n', '\'5\'\n', '\'6\'\n',
244244
'\'7\'\n', '\'8\'\n', '\'9\'\n'].join(`${prompt_unix}`) },
245+
// regression tests for https://github.com/nodejs/node/issues/2749
246+
{ client: client_unix, send: 'function x() {\nreturn \'\\n\';\n }',
247+
expect: prompt_multiline + prompt_multiline +
248+
'undefined\n' + prompt_unix },
249+
{ client: client_unix, send: 'function x() {\nreturn \'\\\\\';\n }',
250+
expect: prompt_multiline + prompt_multiline +
251+
'undefined\n' + prompt_unix },
245252
]);
246253
}
247254

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.