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

Conversation

addaleax
Copy link
Collaborator

@addaleax addaleax commented Sep 5, 2025

Work around the fact that, in some versions of the Node.js REPL,
tab completion may cause side effects.

(First commit is #2529)

mcasimir and others added 2 commits September 5, 2025 00:32
Work around the fact that, in some versions of the Node.js REPL,
tab completion may cause side effects.
@Copilot Copilot AI review requested due to automatic review settings September 5, 2025 17:44
@addaleax addaleax requested a review from a team as a code owner September 5, 2025 17:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a Node.js REPL autocomplete bug (Node.js bug #59774) where tab completion can inadvertently execute code and cause side effects.

  • Implements detection mechanism for the Node.js bug through runtime testing
  • Adds workaround by using older, safer regex patterns for completion when the bug is present
  • Updates Node.js LTS version from 20.19.4 to 20.19.5

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
packages/cli-repl/src/node-repl-fix-completer-side-effects.ts New module implementing bug detection and workaround logic
packages/cli-repl/src/mongosh-repl.ts Integrates the workaround into the REPL completion system
packages/cli-repl/src/mongosh-repl.spec.ts Adds test to verify functions aren't executed during completion
.evergreen/node-20-latest.json Updates Node.js LTS version metadata

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +39 to +47
/^\s*\.(\w*)$/.exec(line) !== null ||
// https://github.com/nodejs/node/blob/07220230d9effcb4822d7a55563a86af3764540c/lib/repl.js#L1226
/\brequire\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])$/.exec(
line
) !== null ||
// https://github.com/nodejs/node/blob/07220230d9effcb4822d7a55563a86af3764540c/lib/repl.js#L1225
/\bimport\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])$/.exec(
line
) !== null ||
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

[nitpick] These complex regex patterns are duplicated from Node.js source and could be extracted into named constants with descriptive names like DOT_COMPLETION_REGEX, REQUIRE_COMPLETION_REGEX, and IMPORT_COMPLETION_REGEX to improve readability and maintainability.

Copilot uses AI. Check for mistakes.

Positive FeedbackNegative Feedback
Comment on lines +60 to +63
const simpleMatch =
/(?:[\w$'"`[{(](?:\w|\$|['"`\]})])*\??\.)*[a-zA-Z_$](?:\w|\$)*\??\.?$/.exec(
line
);
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

[nitpick] This complex regex pattern should be extracted into a named constant like LEGACY_COMPLETION_REGEX with a comment explaining it uses the older, safer pattern from before the Node.js bug was introduced.

Copilot uses AI. Check for mistakes.

Positive FeedbackNegative Feedback
let ranFunction = false;
repl.context.causeSideEffect = () => (ranFunction = true);
try {
await promisify(repl.completer)('causeSideEffect().x');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused by this, why is it trying to access .x in particular? Where is that coming from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a comment here – it doesn't matter which property we try to autocomplete, the important bit is that is is trying to autocomplete a property of the function call result (which it shouldn't evaluate)

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, thank you! the comment is helpful too

@addaleax addaleax merged commit ed1f02d into main Sep 8, 2025
90 of 96 checks passed
@addaleax addaleax deleted the 2635-dev branch September 8, 2025 12:47
@addaleax addaleax mentioned this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

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