-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
|
test/parallel/test-repl.js
Outdated
}, | ||
...possibleTokensAfterIdentifier.map((token) => ( | ||
{ | ||
send: `npm ${token}; undefined`, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
c3f8b21
to
8892202
Compare
test/parallel/test-repl.js
Outdated
{ | ||
send: 'let npm = () => {};', | ||
expect: 'undefined' | ||
}, | ||
...possibleTokensAfterIdentifier.map((token) => ( | ||
{ | ||
send: `npm ${token}; undefined`, | ||
expect: 'undefined' | ||
} | ||
)), | ||
{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed it.
CC @nodejs/repl |
Can you fix the linter error please? |
This comment was marked as outdated.
This comment was marked as outdated.
Landed in 86bdca9 |
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>
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>
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>
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>
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