Skip to content
Merged
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
13 changes: 3 additions & 10 deletions src/main/java/com/github/packageurl/PackageURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,20 +589,13 @@ private static String toLowerCase(String s) {
return new String(chars);
}

private static int indexOfPercentChar(final byte[] bytes, final int start) {
return IntStream.range(start, bytes.length)
private static int indexOfFirstPercentChar(final byte[] bytes) {
return IntStream.range(0, bytes.length)
.filter(i -> isPercent(bytes[i]))
.findFirst()
.orElse(-1);
}

private static int indexOfUnsafeChar(final byte[] bytes, final int start) {
return IntStream.range(start, bytes.length)
.filter(i -> shouldEncode(bytes[i]))
.findFirst()
.orElse(-1);
}

private static byte percentDecode(final byte[] bytes, final int start) {
if (start + 2 >= bytes.length) {
throw new ValidationException("Incomplete percent encoding at offset " + start + " with value '"
Expand Down Expand Up @@ -636,7 +629,7 @@ private static String percentDecode(final String source) {
}

byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
int i = indexOfPercentChar(bytes, 0);
int i = indexOfFirstPercentChar(bytes);

if (i == -1) {
return source;
Expand Down