fix(pnpm): strip leading slashes from pnpm v9 package keys - #1014
Open
Kunal241207 wants to merge 2 commits into
Open
fix(pnpm): strip leading slashes from pnpm v9 package keys#1014Kunal241207 wants to merge 2 commits into
Kunal241207 wants to merge 2 commits into
Conversation
sonukapoor
requested changes
Aug 19, 2026
sonukapoor
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this - the core fix is correct. Two small asks before we merge:
Restore the comments that were removed from these lines - the split("(")[0] for stripping peer-dep suffixes is not obvious to someone reading cold:
// strip leading slash (pnpm v9 can emit /\@babel/core\@7.20.0) then peer-dep suffix (pkg\@1.0.0(peer\@2.0.0))
const cleaned = key.replace(/^\//, "").split("(")[0];
if (idx <= 0) return null; // no @ or @ is the first char (scoped package name only)Two more test cases - the scoped case is covered but please add:
/express\@4.18.2(non-scoped with leading slash - simplest form of the bug)express\@4.18.2(no slash - explicit regression confirming pnpm v8 keys are unaffected)
Quick fixes, then this is good to go.
Contributor
Author
Done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
In
pnpm-lock.yamlv9 lockfiles, package snapshot keys and dependency references can start with a leading slash (for example,'/@babel/core@7.20.0': {}).Previously,
parsePnpmPackageKeyV9andnormalizePnpmDepRefV9stripped peer-dependency suffixes (e.g.(foo@1.0.0)), but did not strip leading slashes/(unlikeparsePnpmPackageKeyfor v5–v8 lockfiles). As a result, package names were stored with leading slashes (e.g.,"/@babel/core"). Whencve-litequeried advisory sources (OSV / local DB) for@babel/core, lookups failed to match, causing affected packages to bypass vulnerability scanning.This PR updates
parsePnpmPackageKeyV9andnormalizePnpmDepRefV9insrc/parsers/pnpm-lock.tsto normalize keys by stripping leading slashes (replace(/^\//, "")), matching legacy pnpm lockfile parsing, and adds test coverage intests/parsers/pnpm-lock.test.ts.Closes #1012