Skip to content

Commit

Permalink
use same test as package-url/purl-spec#273
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-phylum committed Nov 20, 2023
1 parent 46a7904 commit b359e32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions purl_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,26 +1261,26 @@ fn plus_signs_and_spaces() {
);
}
#[test]
/// unsupported: percent signs
fn unsupported_percent_signs() {
/// unsupported: percent signs are properly encoded and decoded
fn unsupported_percent_signs_are_properly_encoded_and_decoded() {
assert!(
matches!(Purl::from_str("pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25"),
matches!(Purl::from_str("pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25"),
Err(PackageError::UnsupportedType)), "Type {} is not supported", "generic"
);
let parsed = match GenericPurl::<String>::from_str(
"pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
) {
Ok(purl) => purl,
Err(error) => {
panic!(
"Failed to parse valid purl {:?}: {}",
"pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
error
)
},
};
assert_eq!("generic", parsed.package_type(), "Incorrect package type");
assert_eq!(Some("@100%"), parsed.namespace(), "Incorrect namespace");
assert_eq!(Some("100%"), parsed.namespace(), "Incorrect namespace");
assert_eq!("100%", parsed.name(), "Incorrect name");
assert_eq!(Some("100%"), parsed.version(), "Incorrect version");
assert_eq!(Some("100%"), parsed.subpath(), "Incorrect subpath");
Expand All @@ -1291,7 +1291,7 @@ fn unsupported_percent_signs() {
parsed.qualifiers().iter().map(|(k, v)| (k.as_str(), v)).collect::<HashMap<&str, &str>>()
);
assert_eq!(
"pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
&parsed.to_string(),
"Incorrect string representation"
);
Expand Down
8 changes: 4 additions & 4 deletions xtask/src/generate_tests/phylum-test-suite-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
"is_invalid": false
},
{
"description": "percent signs",
"purl": "pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"canonical_purl": "pkg:generic/%40100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"description": "percent signs are properly encoded and decoded",
"purl": "pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"canonical_purl": "pkg:generic/100%25/100%25@100%25?repository_url=https://example.com/100%2525/#100%25",
"type": "generic",
"namespace": "@100%",
"namespace": "100%",
"name": "100%",
"version": "100%",
"qualifiers": {
Expand Down

0 comments on commit b359e32

Please sign in to comment.