Skip to content

Commit 5cd1be8

Browse files
committed
Update for review comments
1 parent 569aa42 commit 5cd1be8

1 file changed

Lines changed: 8 additions & 28 deletions

File tree

src/main/java/com/github/packageurl/PackageURL.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.Serializable;
2626
import java.net.URI;
2727
import java.net.URISyntaxException;
28-
import java.nio.charset.Charset;
2928
import java.nio.charset.StandardCharsets;
3029
import java.util.Arrays;
3130
import java.util.Collections;
@@ -460,24 +459,14 @@ private String canonicalize(boolean coordinatesOnly) {
460459
return purl.toString();
461460
}
462461

463-
/**
464-
* Encodes the input in conformance with RFC 3986.
465-
*
466-
* @param input the String to encode
467-
* @return an encoded String
468-
*/
469-
private String percentEncode(final String input) {
470-
return uriEncode(input, StandardCharsets.UTF_8);
471-
}
472-
473-
private static String uriEncode(String source, Charset charset) {
462+
private static String percentEncode(final String source) {
474463
if (source == null || source.isEmpty()) {
475464
return source;
476465
}
477466

478-
byte[] bytes = source.getBytes(charset);
467+
byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
479468
int length = bytes.length;
480-
int pos = indexOfFirstUnreservedChar(bytes);
469+
int pos = indexOfFirstUnsafeChar(bytes);
481470

482471
if (pos == -1) {
483472
return source;
@@ -500,7 +489,7 @@ private static String uriEncode(String source, Charset charset) {
500489
return builder.toString();
501490
}
502491

503-
private static int indexOfFirstUnreservedChar(final byte[] bytes) {
492+
private static int indexOfFirstUnsafeChar(final byte[] bytes) {
504493
final int length = bytes.length;
505494
int pos = -1;
506495

@@ -573,23 +562,14 @@ private static String toLowerCase(String s) {
573562
return new String(chars);
574563
}
575564

576-
/**
577-
* Optionally decodes a String, if it's encoded. If String is not encoded,
578-
* method will return the original input value.
579-
*
580-
* @param input the value String to decode
581-
* @return a decoded String
582-
*/
583-
private String percentDecode(final String input) {
584-
return uriDecode(input);
585-
}
586-
587-
public static String uriDecode(String source) {
565+
public static String percentDecode(final String source) {
588566
if (source == null || source.isEmpty()) {
589567
return source;
590568
}
591569

592-
if (source.indexOf('%') == -1) {
570+
int firstPercent = source.indexOf('%');
571+
572+
if (firstPercent == -1) {
593573
return source;
594574
}
595575

0 commit comments

Comments
 (0)