Skip to content

Commit a1b8a9d

Browse files
jcrossley3ctron
authored andcommitted
fix: encode '+' per the latest version of the spec
See https://github.com/package-url/purl-spec/blob/main/PURL-SPECIFICATION.rst#character-encoding "All other characters MUST be encoded as UTF-8 and then percent-encoded"
1 parent 72c0a2f commit a1b8a9d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/purl.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS
3030
// .add(b':')
3131
.add(b';')
3232
.add(b'=')
33+
.add(b'+')
3334
.add(b'@')
3435
.add(b'\\')
3536
.add(b'[')
@@ -406,7 +407,7 @@ mod tests {
406407
)
407408
.unwrap();
408409
let encoded = purl.to_string();
409-
assert_eq!(encoded, "pkg:deb/ubuntu/gnome-calculator@1:41.1-2ubuntu2?vcs_url=git+https://salsa.debian.org/gnome-team/gnome-calculator.git%40debian/1%2541.1-2");
410+
assert_eq!(encoded, "pkg:deb/ubuntu/gnome-calculator@1:41.1-2ubuntu2?vcs_url=git%2Bhttps://salsa.debian.org/gnome-team/gnome-calculator.git%40debian/1%2541.1-2");
410411
}
411412

412413
#[cfg(feature = "serde")]
@@ -427,4 +428,17 @@ mod tests {
427428

428429
assert_eq!(purl, purl2);
429430
}
431+
432+
#[test]
433+
fn test_plus_sign_in_version() {
434+
let expected = "pkg:type/name@1%2Bx";
435+
for purl in [
436+
"pkg:type/name@1+x",
437+
"pkg:type/name@1%2bx",
438+
"pkg:type/name@1%2Bx",
439+
] {
440+
let actual = PackageUrl::from_str(purl).unwrap().to_string();
441+
assert_eq!(actual, expected);
442+
}
443+
}
430444
}

0 commit comments

Comments
 (0)