From 053c58b31d5a36030528a1ac21cf8ee02adade44 Mon Sep 17 00:00:00 2001 From: rmealing Date: Tue, 28 Sep 2021 21:36:28 +0100 Subject: [PATCH] Account for NPM being case-sensitive --- .../com/github/packageurl/PackageURL.java | 2 -- .../com/github/packageurl/PackageURLTest.java | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/github/packageurl/PackageURL.java b/src/main/java/com/github/packageurl/PackageURL.java index 3dbeed0..45cabb4 100644 --- a/src/main/java/com/github/packageurl/PackageURL.java +++ b/src/main/java/com/github/packageurl/PackageURL.java @@ -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; @@ -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: diff --git a/src/test/java/com/github/packageurl/PackageURLTest.java b/src/test/java/com/github/packageurl/PackageURLTest.java index 37fca70..4f38b16 100644 --- a/src/test/java/com/github/packageurl/PackageURLTest.java +++ b/src/test/java/com/github/packageurl/PackageURLTest.java @@ -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; @@ -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 *

@@ -303,4 +303,19 @@ public void testGetCoordinates() throws Exception { PackageURL purl = new PackageURL("pkg:generic/acme/example-component@1.0.0?key1=value1&key2=value2"); Assert.assertEquals("pkg:generic/acme/example-component@1.0.0", 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/base64@1.0.0"); + 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/Base64@1.0.0"); + Assert.assertEquals(base64Uppercase.getType(), "npm"); + Assert.assertEquals(base64Uppercase.getName(), "Base64"); + Assert.assertEquals(base64Uppercase.getVersion(), "1.0.0"); + } }