Skip to content

Commit

Permalink
Fix for issue-58 - incorrect parsing of PURLs begining with pkg://
Browse files Browse the repository at this point in the history
  • Loading branch information
aniruth37 committed Dec 6, 2023
1 parent 163eec5 commit 06c7d20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/package-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class PackageURL {
}
type = decodeURIComponent(type)

let url = new URL(purl);
// strip /, // and /// as possible in pkg:/ or pkg:// or pkg:///
let url = new URL(purl.trim().replace(/^pkg:\/+/g, 'pkg:'));

let qualifiers = null;
url.searchParams.forEach((value, key) => {
Expand All @@ -175,9 +176,7 @@ class PackageURL {
throw new Error('Invalid purl: cannot contain a "user:pass@host:port"');
}

// this strip '/, // and /// as possible in :// or :///
// from https://gist.github.com/refo/47632c8a547f2d9b6517#file-remove-leading-slash
let path = url.pathname.trim().replace(/^\/+/g, '');
let path = url.pathname.trim();

// version is optional - check for existence
let version = null;
Expand Down

0 comments on commit 06c7d20

Please sign in to comment.