Skip to content
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: don’t write to input stream in editor mode #9207

Closed
wants to merge 3 commits into from

Conversation

addaleax
Copy link
Member

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

repl

Description of change
  • In .editor mode, repl.write() would have crashed when the key argument was not present, because the overwritten _ttyWrite of REPLs doesn’t check for the absence of a second argument like readline.write() does.
    Since the docs indicate that the argument is optional, add a check paralleling the one in readline.write().
  • Instead of writing to the REPL’s input stream for the alignment
    spaces in .editor mode, let readline handle the spaces
    properly (echoing them using _ttyWrite and adding them to the
    current line buffer).

Fixes: #9189

In `.editor` mode, `repl.write()` would have crashed when the
`key` argument was not present, because the overwritten
`_ttyWrite` of REPLs doesn’t check for the absence of a second
argument like `readline.write()` does.

Since the docs indicate that the argument is optional, add
a check paralleling the one in `readline.write()`.
@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Oct 20, 2016
@addaleax
Copy link
Member Author


if (!checkTerminalCodes) {
while (found.includes(terminalCode))
found = found.replace(terminalCode, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax quoted terminal code is sufficient right?
const terminalCodeRegex = /\u001b\[1G\u001b\[0J> \u001b\[3G/g

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@princejwesley Yeah, I’ve updated it to use a regex… I’m not particularly a fan of duplicating strings that are hard to scan, but if you prefer a plain regex literal over what I’ve just pushed, I can go with that too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax 👍 Just to convey the term 'quoted' correctly, added code snippet with [ escaped manually 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@princejwesley ok, seems like we’re on the same page then 😄

Instead of writing to the REPL’s input stream for the alignment
spaces in `.editor` mode, let `readline` handle the spaces
properly (echoing them using `_ttyWrite` and adding them to the
current line buffer).

Fixes: nodejs#9189
Copy link
Contributor

@princejwesley princejwesley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@addaleax
Copy link
Member Author

Landed in 8b6fd43 and 3dfc127

addaleax added a commit that referenced this pull request Oct 26, 2016
In `.editor` mode, `repl.write()` would have crashed when the
`key` argument was not present, because the overwritten
`_ttyWrite` of REPLs doesn’t check for the absence of a second
argument like `readline.write()` does.

Since the docs indicate that the argument is optional, add
a check paralleling the one in `readline.write()`.

PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit that referenced this pull request Oct 26, 2016
Instead of writing to the REPL’s input stream for the alignment
spaces in `.editor` mode, let `readline` handle the spaces
properly (echoing them using `_ttyWrite` and adding them to the
current line buffer).

Fixes: #9189
PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax addaleax closed this Oct 26, 2016
@addaleax addaleax deleted the fix-repl-write-editor-mode branch October 26, 2016 19:49
evanlucas pushed a commit that referenced this pull request Nov 3, 2016
In `.editor` mode, `repl.write()` would have crashed when the
`key` argument was not present, because the overwritten
`_ttyWrite` of REPLs doesn’t check for the absence of a second
argument like `readline.write()` does.

Since the docs indicate that the argument is optional, add
a check paralleling the one in `readline.write()`.

PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request Nov 3, 2016
Instead of writing to the REPL’s input stream for the alignment
spaces in `.editor` mode, let `readline` handle the spaces
properly (echoing them using `_ttyWrite` and adding them to the
current line buffer).

Fixes: #9189
PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

@addaleax lts?

@addaleax
Copy link
Member Author

@thealphanerd v6.x only, but yes

MylesBorins pushed a commit that referenced this pull request Nov 22, 2016
In `.editor` mode, `repl.write()` would have crashed when the
`key` argument was not present, because the overwritten
`_ttyWrite` of REPLs doesn’t check for the absence of a second
argument like `readline.write()` does.

Since the docs indicate that the argument is optional, add
a check paralleling the one in `readline.write()`.

PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Nov 22, 2016
Instead of writing to the REPL’s input stream for the alignment
spaces in `.editor` mode, let `readline` handle the spaces
properly (echoing them using `_ttyWrite` and adding them to the
current line buffer).

Fixes: #9189
PR-URL: #9207
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Nov 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants