Skip to content

Commit a98c7fb

Browse files
authored
fix plus sign bug (#54)
1 parent 3fa7a38 commit a98c7fb

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.github/workflows/ci.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Run Unit Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- '**'
6+
jobs:
7+
unit_test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- run: |
12+
npm ci
13+
npm run test

src/package-url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class PackageURL {
104104

105105
if (this.version) {
106106
purl.push('@');
107-
purl.push(encodeURIComponent(this.version).replace(/%3A/g, ':'));
107+
purl.push(encodeURIComponent(this.version).replace(/%3A/g, ':').replace(/%2B/g,'+'));
108108
}
109109

110110
if (this.qualifiers) {
@@ -188,7 +188,7 @@ class PackageURL {
188188
// Convert percent-encoded colons (:) back, to stay in line with the `toString`
189189
// implementation of this library.
190190
// https://github.com/package-url/packageurl-js/blob/58026c86978c6e356e5e07f29ecfdccbf8829918/src/package-url.js#L98C10-L98C10
191-
let versionEncoded = encodeURIComponent(version).replace(/%3A/g, ':');
191+
let versionEncoded = encodeURIComponent(version).replace(/%3A/g, ':').replace(/%2B/g,'+');
192192

193193
if (rawVersion !== versionEncoded) {
194194
throw new Error('Invalid purl: version must be percent-encoded');

test/data/test-suite-data.json

+12
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@
107107
"subpath": null,
108108
"is_invalid": false
109109
},
110+
{
111+
"description": "debian can have debian versions as part of version with plus sign",
112+
"purl": "pkg:deb/debian/libssl1.1@1.1.1n-0+deb10u3?arch=amd64&distro=debian-10",
113+
"canonical_purl": "pkg:deb/debian/libssl1.1@1.1.1n-0+deb10u3?arch=amd64&distro=debian-10",
114+
"type": "deb",
115+
"namespace": "debian",
116+
"name": "libssl1.1",
117+
"version": "1.1.1n-0+deb10u3",
118+
"qualifiers": {"arch": "amd64", "distro": "debian-10"},
119+
"subpath": null,
120+
"is_invalid": false
121+
},
110122
{
111123
"description": "docker uses qualifiers and hash image id as versions",
112124
"purl": "pkg:docker/customer/dockerimage@sha256:244fd47e07d1004f0aed9c?repository_url=gcr.io",

0 commit comments

Comments
 (0)