-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: backslashes confuse the multiline parser #2749
Comments
Mmmm, this is because the readline module parsing |
It's not just |
Looks to be a pretty recent regression, 0.12 works. |
@silverwind It's after this 81ea52a. Before that the string was accumulated no matter what, till the evaluation of accumulated string is successful. But that commit keeps track of the quotes to detect the string literals. |
Can confirm I got this problem too when trying the hello world server from the website about page in the REPL. |
@silverwind I think we'll have to revert 81ea52a to fix this problem. cc @Fishrock123 |
👍 for the revert. Being unable to paste any multi-line code containing backslashes warrents it imho. |
@thefourtheye want to attempt the revert yourself? (We could probably use some documentation for reverting) |
When some string is copied and pasted in REPL, if it has a newline (\n) in it, then it is considered as end of line and REPL throws a SyntaxError, because a line cannot end with a unclosed string literal. This behavior is because of the fact that `readline` module breaks at all the `\n`s in the input string and treats them as a seperate line. So whenever it encounters a new line character it will emit a `line` event. This commit basically reverts nodejs@81ea52a, which was an attempt to improve the way string literals were handled by REPL. Fixes: nodejs#2749
@silverwind Sorry, I was out playing badminton :D Please take a look at the commit log of the bug fix and let me know if that has to be improved. |
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: nodejs#2952 Fixes: nodejs#2749
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>
Fixed by fcfd87d |
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>
Pasting this into the REPL:
results in
cc: @thefourtheye
The text was updated successfully, but these errors were encountered: