Skip to content

Commit 6eb2a01

Browse files
Removed unnecessary cache of canonicalized form leadingn to unexpected behavior. Updated unit tests
1 parent 4b812de commit 6eb2a01

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/main/java/com/github/packageurl/PackageURL.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ public PackageURL(final String type, final String namespace, final String name,
149149
*/
150150
private String subpath;
151151

152-
/**
153-
* The cached version of the canonical form.
154-
*/
155-
private String canonicalizedForm = null;
156-
157152
/**
158153
* Returns the package url scheme.
159154
*
@@ -387,9 +382,6 @@ public String canonicalize() {
387382
* @since 1.3.2
388383
*/
389384
private String canonicalize(boolean coordinatesOnly) {
390-
if (canonicalizedForm != null) {
391-
return canonicalizedForm;
392-
}
393385
final StringBuilder purl = new StringBuilder();
394386
purl.append(scheme).append(":");
395387
if (type != null) {
@@ -421,8 +413,7 @@ private String canonicalize(boolean coordinatesOnly) {
421413
purl.append("#").append(encodePath(subpath));
422414
}
423415
}
424-
canonicalizedForm = purl.toString();
425-
return canonicalizedForm;
416+
return purl.toString();
426417
}
427418

428419
/**

src/test/java/com/github/packageurl/PackageURLTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ public void testGetCoordinates() throws Exception {
306306
Assert.assertEquals("pkg:generic/acme/example-component@1.0.0", purl.getCoordinates());
307307
}
308308

309+
@Test
310+
public void testGetCoordinatesNoCacheIssue89() throws Exception {
311+
PackageURL purl = new PackageURL("pkg:generic/acme/example-component@1.0.0?key1=value1&key2=value2");
312+
purl.canonicalize();
313+
Assert.assertEquals("pkg:generic/acme/example-component@1.0.0", purl.getCoordinates());
314+
}
315+
309316
@Test
310317
public void testNpmCaseSensitive() throws Exception {
311318
// e.g. https://www.npmjs.com/package/base64/v/1.0.0

0 commit comments

Comments
 (0)