Skip to content

Commit

Permalink
Merge pull request #38 from mealingr/npm_case_sensitive
Browse files Browse the repository at this point in the history
Account for NPM being case-sensitive
  • Loading branch information
stevespringett authored Sep 29, 2021
2 parents aa029fe + 053c58b commit 649f4c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/github/packageurl/PackageURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ private String validateNamespace(final String[] values) throws MalformedPackageU
case StandardTypes.DEBIAN:
case StandardTypes.GITHUB:
case StandardTypes.GOLANG:
case StandardTypes.NPM:
case StandardTypes.RPM:
retVal = tempNamespace.toLowerCase();
break;
Expand All @@ -286,7 +285,6 @@ private String validateName(final String value) throws MalformedPackageURLExcept
case StandardTypes.DEBIAN:
case StandardTypes.GITHUB:
case StandardTypes.GOLANG:
case StandardTypes.NPM:
temp = value.toLowerCase();
break;
case StandardTypes.PYPI:
Expand Down
23 changes: 19 additions & 4 deletions src/test/java/com/github/packageurl/PackageURLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/
package com.github.packageurl;

import java.io.IOException;
import java.io.InputStream;
import java.util.TreeMap;

import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -30,10 +34,6 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.io.InputStream;
import java.util.TreeMap;

/**
* Test cases for PackageURL parsing
* <p>
Expand Down Expand Up @@ -303,4 +303,19 @@ public void testGetCoordinates() throws Exception {
PackageURL purl = new PackageURL("pkg:generic/acme/[email protected]?key1=value1&key2=value2");
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
PackageURL base64Lowercase = new PackageURL("pkg:npm/[email protected]");
Assert.assertEquals(base64Lowercase.getType(), "npm");
Assert.assertEquals(base64Lowercase.getName(), "base64");
Assert.assertEquals(base64Lowercase.getVersion(), "1.0.0");

// e.g. https://www.npmjs.com/package/Base64/v/1.0.0
PackageURL base64Uppercase = new PackageURL("pkg:npm/[email protected]");
Assert.assertEquals(base64Uppercase.getType(), "npm");
Assert.assertEquals(base64Uppercase.getName(), "Base64");
Assert.assertEquals(base64Uppercase.getVersion(), "1.0.0");
}
}

0 comments on commit 649f4c5

Please sign in to comment.