Skip to content

Commit

Permalink
resolving npm namespace issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Moullisha authored and jdalton committed May 18, 2024
1 parent b6e5902 commit b59b5a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/package-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class PackageURL {

// version is optional - check for existence
let version = undefined;
const atSignIndex = path.indexOf('@');
const atSignIndex = path.lastIndexOf('@');
if (atSignIndex !== -1) {
const rawVersion = path.slice(atSignIndex + 1);
version = decodeURIComponent(rawVersion);
Expand Down
10 changes: 10 additions & 0 deletions test/package-url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ describe('PackageURL', function () {
})
});

it('npm PURL with namespace starting with @', function () {
const purlString = 'pkg:npm/@aws-crypto/[email protected]'
const purl = PackageURL.fromString(purlString)

assert.strictEqual(purl.type, 'npm')
assert.strictEqual(purl.namespace, '@aws-crypto')
assert.strictEqual(purl.name, 'crc32')
assert.strictEqual(purl.version, '3.0.0')
});

it('namespace with multiple segments', function () {
const purl = PackageURL.fromString('pkg:ty%2Fpe/namespace1/namespace2/na%2Fme')
assert.strictEqual('ty/pe', purl.type)
Expand Down

0 comments on commit b59b5a3

Please sign in to comment.