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: avoid interpreting 'npm' as a command when errors are recoverable #54848

Merged
merged 4 commits into from
Sep 15, 2024

Conversation

islandryu
Copy link
Contributor

This change ensures that 'npm' within JavaScript code is not mistakenly interpreted as an npm command when the error is recoverable. This allows 'npm' to be treated as expected in such scenarios.

Fixes: #54830

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Sep 8, 2024
Copy link

codecov bot commented Sep 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.06%. Comparing base (dcc2ed9) to head (2bdc4a4).
Report is 76 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54848      +/-   ##
==========================================
+ Coverage   87.62%   88.06%   +0.43%     
==========================================
  Files         650      651       +1     
  Lines      182983   183388     +405     
  Branches    35406    35800     +394     
==========================================
+ Hits       160336   161496    +1160     
+ Misses      15917    15160     -757     
- Partials     6730     6732       +2     
Files with missing lines Coverage Δ
lib/repl.js 94.86% <100.00%> (+0.74%) ⬆️

... and 105 files with indirect coverage changes

},
...possibleTokensAfterIdentifier.map((token) => (
{
send: `npm ${token}; undefined`,
Copy link
Member

@RedYetiDev RedYetiDev Sep 8, 2024

Choose a reason for hiding this comment

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

Nice idea, that's definitely the right path... however the test right here isn't an accurate measurement of whether this works. The tests for NPM need to be a recoverable error, however these lines are valid JS.

Try adding a newline character in the middle of the recoverable statement to see if it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT this test already passes on main. A test that validates this change should fail on main and pass on the PR branch.

Copy link
Member

Choose a reason for hiding this comment

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

That's the issue with the test. The test needs to throw a recoverable syntax error, however these are valid JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, with this, it doesn't go through the recoverable error path.
I have added new tests with line breaks included.

This change ensures that 'npm' within JavaScript code is not mistakenly
interpreted as an npm command when the error is recoverable.
This allows 'npm' to be treated as expected in such scenarios.

Fixes: nodejs#54830
Comment on lines 412 to 422
{
send: 'let npm = () => {};',
expect: 'undefined'
},
...possibleTokensAfterIdentifier.map((token) => (
{
send: `npm ${token}; undefined`,
expect: 'undefined'
}
)),
{
Copy link
Member

Choose a reason for hiding this comment

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

I dont think this test is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed it.

@RedYetiDev RedYetiDev removed their request for review September 9, 2024 15:39
@RedYetiDev
Copy link
Member

CC @nodejs/repl

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Sep 11, 2024
@aduh95
Copy link
Contributor

aduh95 commented Sep 11, 2024

Can you fix the linter error please?

@aduh95 aduh95 removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 11, 2024
@RedYetiDev RedYetiDev added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Sep 11, 2024
@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 13, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 13, 2024
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@cola119 cola119 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. labels Sep 15, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 15, 2024
@nodejs-github-bot nodejs-github-bot merged commit 86bdca9 into nodejs:main Sep 15, 2024
62 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 86bdca9

RafaelGSS pushed a commit that referenced this pull request Sep 16, 2024
This change ensures that 'npm' within JavaScript code is not mistakenly
interpreted as an npm command when the error is recoverable.
This allows 'npm' to be treated as expected in such scenarios.

Fixes: #54830
PR-URL: #54848
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
@RafaelGSS RafaelGSS mentioned this pull request Sep 16, 2024
RafaelGSS pushed a commit that referenced this pull request Sep 16, 2024
This change ensures that 'npm' within JavaScript code is not mistakenly
interpreted as an npm command when the error is recoverable.
This allows 'npm' to be treated as expected in such scenarios.

Fixes: #54830
PR-URL: #54848
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Sep 17, 2024
This change ensures that 'npm' within JavaScript code is not mistakenly
interpreted as an npm command when the error is recoverable.
This allows 'npm' to be treated as expected in such scenarios.

Fixes: #54830
PR-URL: #54848
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Sep 17, 2024
This change ensures that 'npm' within JavaScript code is not mistakenly
interpreted as an npm command when the error is recoverable.
This allows 'npm' to be treated as expected in such scenarios.

Fixes: #54830
PR-URL: #54848
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL doesn't handle npm correctly
7 participants