Skip to content

Commit

Permalink
Removed unnecessary cache of canonicalized form leadingn to unexpecte…
Browse files Browse the repository at this point in the history
…d behavior. Updated unit tests
  • Loading branch information
stevespringett committed Nov 8, 2023
1 parent 4b812de commit 6eb2a01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/main/java/com/github/packageurl/PackageURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ public PackageURL(final String type, final String namespace, final String name,
*/
private String subpath;

/**
* The cached version of the canonical form.
*/
private String canonicalizedForm = null;

/**
* Returns the package url scheme.
*
Expand Down Expand Up @@ -387,9 +382,6 @@ public String canonicalize() {
* @since 1.3.2
*/
private String canonicalize(boolean coordinatesOnly) {
if (canonicalizedForm != null) {
return canonicalizedForm;
}
final StringBuilder purl = new StringBuilder();
purl.append(scheme).append(":");
if (type != null) {
Expand Down Expand Up @@ -421,8 +413,7 @@ private String canonicalize(boolean coordinatesOnly) {
purl.append("#").append(encodePath(subpath));
}
}
canonicalizedForm = purl.toString();
return canonicalizedForm;
return purl.toString();
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/github/packageurl/PackageURLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ public void testGetCoordinates() throws Exception {
Assert.assertEquals("pkg:generic/acme/[email protected]", purl.getCoordinates());
}

@Test
public void testGetCoordinatesNoCacheIssue89() throws Exception {
PackageURL purl = new PackageURL("pkg:generic/acme/[email protected]?key1=value1&key2=value2");
purl.canonicalize();
Assert.assertEquals("pkg:generic/acme/[email protected]", purl.getCoordinates());
}

@Test
public void testNpmCaseSensitive() throws Exception {
// e.g. https://www.npmjs.com/package/base64/v/1.0.0
Expand Down

0 comments on commit 6eb2a01

Please sign in to comment.