Skip to content

Commit 30bd019

Browse files
Merge pull request #102 from package-url/fix-issue-89
Removed unnecessary cache of canonicalized form
2 parents 93fadd6 + 6eb2a01 commit 30bd019

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
@@ -146,11 +146,6 @@ public PackageURL(final String type, final String namespace, final String name,
146146
*/
147147
private String subpath;
148148

149-
/**
150-
* The cached version of the canonical form.
151-
*/
152-
private String canonicalizedForm = null;
153-
154149
/**
155150
* Returns the package url scheme.
156151
*
@@ -384,9 +379,6 @@ public String canonicalize() {
384379
* @since 1.3.2
385380
*/
386381
private String canonicalize(boolean coordinatesOnly) {
387-
if (canonicalizedForm != null) {
388-
return canonicalizedForm;
389-
}
390382
final StringBuilder purl = new StringBuilder();
391383
purl.append(scheme).append(":");
392384
if (type != null) {
@@ -418,8 +410,7 @@ private String canonicalize(boolean coordinatesOnly) {
418410
purl.append("#").append(encodePath(subpath));
419411
}
420412
}
421-
canonicalizedForm = purl.toString();
422-
return canonicalizedForm;
413+
return purl.toString();
423414
}
424415

425416
/**

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)