Skip to content

Commit

Permalink
Support latest spec test data
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Esser <[email protected]>
  • Loading branch information
steven-esser committed May 16, 2024
1 parent 09776a6 commit 2a4018a
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 146 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.

30 changes: 28 additions & 2 deletions src/package-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ class PackageURL {
}
});
}

if (type === 'conan') {
if (qualifiers) {
if (qualifiers.hasOwnProperty('channel') && !namespace) {
throw new Error('Invalid purl: conan has only channel qualifiers.');
}
}
if (namespace && !qualifiers) {
throw new Error('Invalid purl: conan has only namespace.');
}
}

if (type === 'cran') {
if (!version) {
throw new Error('Invalid purl: cran requires a version.');
}
}

if (type === 'swift') {
if (!namespace) {
throw new Error('Invalid purl: swift has no namespace.');
}
if (!version) {
throw new Error('Invalid purl: swift requires a version.');
}
}

this.type = type;
this.name = name;
Expand Down Expand Up @@ -104,7 +130,7 @@ class PackageURL {

if (this.version) {
purl.push('@');
purl.push(encodeURIComponent(this.version));
purl.push(encodeURIComponent(this.version).replace(/%3A/g, ':'));
}

if (this.qualifiers) {
Expand All @@ -116,7 +142,7 @@ class PackageURL {
qualifierString.push(
encodeURIComponent(key).replace(/%3A/g, ':')
+ '='
+ encodeURIComponent(qualifiers[key]).replace(/%2F/g, '/')
+ encodeURIComponent(qualifiers[key]).replace(/%3A/g, ':').replace(/%2F/g, '/')
);
});

Expand Down
Loading

0 comments on commit 2a4018a

Please sign in to comment.