-
Notifications
You must be signed in to change notification settings - Fork 152
Fix PURL parsing to prevent mismatch for scoped packages #1008
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
Fix PURL parsing to prevent mismatch for scoped packages #1008
Conversation
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.
Pull Request Overview
This PR fixes a bug where scoped npm packages (e.g., @netdata/charts) were incorrectly handled in license checking due to double-encoding of package URLs. The fix removes unnecessary encodeURI() call since PURLs from the Dependency Graph API are already properly formatted and parsePURL() handles decoding internally.
- Removed redundant
encodeURI()call that was double-encoding already-encoded package URLs - Updated
@types/jestdependency to latest patch version
Reviewed Changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/licenses.ts | Removed encodeURI() wrapper to prevent double-encoding of package URLs when parsing |
| package.json | Updated @types/jest from 29.5.12 to 29.5.14 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
dangoor
left a comment
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.
This makes sense! Thanks for the fix!
fb05a7c to
f620fd1
Compare
The issue was that
encodeURI(change.package_url)was encoding already encoded URLs. For example, for a package with PURLpkg:npm/@netdata/chartsafter encoding withencodeURI()would be:pkg:npm/%40netdata/charts.Removing this unnecessary encoding prevents the mismatch issue in #1006
The fix would be to modify line 177 in licenses.ts to remove the use of the
encodeURI()method. From what I understand, theparsePURL()function in purl.ts already handles URI decoding properly withdecodeURIComponent()and PURLs from the Dependency Graph API are (notionally) already properly formatted. The license exclusions list would contain the normal, unencoded package URLs and so the namespace comparison on line 186 of licenses.ts will no longer always returnfalse, thereby excluding scoped packages inallow-dependencies-licensesfrom the license check.AFAIK, this change should be safe because:
parsePURL()can handle both encoded and unencoded URLsdecodeURIComponent()is used to normalise the namespace and name.Closes: #1006