Skip to content

Commit

Permalink
package-url#150 Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nhumblot committed Jun 1, 2024
1 parent 9057afa commit 7bd4231
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/java/com/github/packageurl/PackageURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -437,16 +436,16 @@ private String canonicalize(boolean coordinatesOnly) {
* @return an encoded String
*/
private String percentEncode(final String input) {
return uriEncode(input, StandardCharsets.UTF_8);
return uriEncode(input);
}

private static String uriEncode(String source, Charset charset) {
if (source == null || source.length() == 0) {
private static String uriEncode(String source) {
if (source == null || source.isEmpty()) {
return source;
}

StringBuilder builder = new StringBuilder();
for (byte b : source.getBytes(charset)) {
for (byte b : source.getBytes(StandardCharsets.UTF_8)) {
if (isUnreserved(b)) {
builder.append((char) b);
}
Expand Down

0 comments on commit 7bd4231

Please sign in to comment.