Skip to content

Commit 3ad90dd

Browse files
committed
Update precent encoding
1 parent fbac3b4 commit 3ad90dd

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,21 +446,19 @@ private static String percentEncode(final String source) {
446446
return source;
447447
}
448448

449-
StringBuilder builder = new StringBuilder(source.substring(0, pos));
450-
451-
for (int i = pos; i < length; i++) {
452-
byte b = bytes[i];
449+
StringBuilder sb = new StringBuilder(length * 3);
453450

451+
for (byte b : bytes) {
454452
if (isUnreserved(b)) {
455-
builder.append((char) b);
453+
sb.append((char) b);
456454
} else {
457-
builder.append('%');
458-
builder.append(Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)));
459-
builder.append(Character.toUpperCase(Character.forDigit(b & 0xF, 16)));
455+
sb.append('%');
456+
sb.append(Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)));
457+
sb.append(Character.toUpperCase(Character.forDigit(b & 0xF, 16)));
460458
}
461459
}
462460

463-
return builder.toString();
461+
return sb.toString();
464462
}
465463

466464
private static int indexOfFirstUnsafeChar(final byte[] bytes) {

0 commit comments

Comments
 (0)