-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: recognize allowScripts for local link targets #9490
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,56 @@ t.test('file path — exact resolved match', t => { | |
| t.end() | ||
| }) | ||
|
|
||
| t.test('file path — link target matches incoming link source', t => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a negative case here? A registry node (resolved = tarball URL, empty |
||
| const targetPath = require('node:path').resolve('local-pkg') | ||
| const target = node({ | ||
| name: 'local-pkg', | ||
| packageName: 'local-pkg', | ||
| version: '1.0.0', | ||
| }) | ||
| target.resolved = null | ||
| target.path = targetPath | ||
| target.realpath = targetPath | ||
| target.linksIn = new Set([{ resolved: 'file:../local-pkg' }]) | ||
|
|
||
| t.equal(isScriptAllowed(target, { 'file:../local-pkg': true }), true) | ||
| t.equal(isScriptAllowed(target, { 'file:local-pkg': true }), true) | ||
| t.equal(isScriptAllowed(target, { 'file:../local-pkg': false }), false) | ||
| t.equal(isScriptAllowed(target, { 'file:../other': true }), null) | ||
| t.end() | ||
| }) | ||
|
|
||
| t.test('file path — registry nodes do not match by install path', t => { | ||
| const reg = node({ | ||
| name: 'sharp', | ||
| packageName: 'sharp', | ||
| version: '0.33.0', | ||
| path: 'node_modules/sharp', | ||
| realpath: require('node:path').resolve('node_modules/sharp'), | ||
| linksIn: new Set(), | ||
| }) | ||
|
|
||
| t.equal(isScriptAllowed(reg, { 'file:node_modules/sharp': true }), null) | ||
| t.end() | ||
| }) | ||
|
|
||
| t.test('file path — empty link sets do not add install paths', t => { | ||
| const targetPath = require('node:path').resolve('local-pkg') | ||
| const target = node({ | ||
| name: 'local-pkg', | ||
| packageName: 'local-pkg', | ||
| version: '1.0.0', | ||
| }) | ||
| target.resolved = null | ||
| target.path = targetPath | ||
| target.realpath = targetPath | ||
| target.linksIn = new Set() | ||
|
|
||
| t.equal(isScriptAllowed(target, { 'file:local-pkg': true }), null) | ||
| t.equal(isScriptAllowed(target, { [targetPath]: true }), null) | ||
| t.end() | ||
| }) | ||
|
|
||
| t.test('directory key — npa parses absolute paths as type=directory', t => { | ||
| // npa treats absolute paths as { type: 'directory' }, which the | ||
| // matcher shares with the 'file' case. path.resolve produces a | ||
|
|
||
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.
The same root cause leaks into the writer. If a link target has an empty
linksIn(soresolvedis null),resolvedSourceSpecs(node)[0]isnode.realpath, an absolute path.versionedKeyFor/nameKeyForthen take thestartsWith('/')branch and write something like/proj/node_modules/AintoallowScriptsinstead offile:../A. Better to prefer afile:candidate over a bare path, or return null so we don't persist a machine-specific key. Fixing comment 1 with thesize > 0guard mostly covers this too.