forked from package-url/packageurl-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The methods `uriEncode` and `uriDecode` did not properly handle percent-encoding. In particular, `uriEncode` didn't properly output two uppercase hex digits and `urlDecode` did not properly handle non-ASCII characters. Fixes package-url#150 Closes package-url#153 Fixes package-url#154
- Loading branch information
Showing
2 changed files
with
56 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.TreeMap; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
@@ -55,6 +57,26 @@ public static void setup() throws IOException { | |
json = new JSONArray(jsonTxt); | ||
} | ||
|
||
@Test | ||
public void testEncoding1() throws MalformedPackageURLException { | ||
PackageURL purl = new PackageURL("maven", "com.google.summit", "summit-ast", "2.2.0\n", null, null); | ||
Assert.assertEquals("pkg:maven/com.google.summit/[email protected]%0A", purl.toString()); | ||
} | ||
|
||
@Test | ||
public void testEncoding2() throws MalformedPackageURLException { | ||
PackageURL purl = new PackageURL("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5"); | ||
// d09c6963726f73d0be66742ed0956e746974d1834672616dd0b5776f726bd0a1d0be72d0b5 | ||
|
||
byte[] ba = purl.getName().getBytes(StandardCharsets.UTF_8); | ||
StringBuilder str = new StringBuilder(); | ||
for (byte b : ba) str.append(String.format("%x", b)); | ||
String s = str.toString(); | ||
System.out.println("XXX: " + s); | ||
Assert.assertEquals("Мicrosоft.ЕntitуFramеworkСоrе", purl.getName()); | ||
Assert.assertEquals("pkg:nuget/%D0%9Cicros%D0%BEft.%D0%95ntit%D1%83Fram%D0%B5work%D0%A1%D0%BEr%D0%B5", purl.toString()); | ||
} | ||
|
||
@Test | ||
public void testConstructorParsing() throws Exception { | ||
exception = ExpectedException.none(); | ||
|