Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for NPM being case-sensitive #38

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}