Skip to content

Commit 8475ad4

Browse files
committed
Update precent encoding
1 parent 5cd1be8 commit 8475ad4

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,19 @@ private static String percentEncode(final String source) {
472472
return source;
473473
}
474474

475-
StringBuilder builder = new StringBuilder(source.substring(0, pos));
476-
477-
for (int i = pos; i < length; i++) {
478-
byte b = bytes[i];
475+
StringBuilder sb = new StringBuilder(length * 3);
479476

477+
for (byte b : bytes) {
480478
if (isUnreserved(b)) {
481-
builder.append((char) b);
479+
sb.append((char) b);
482480
} else {
483-
builder.append('%');
484-
builder.append(Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)));
485-
builder.append(Character.toUpperCase(Character.forDigit(b & 0xF, 16)));
481+
sb.append('%');
482+
sb.append(Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)));
483+
sb.append(Character.toUpperCase(Character.forDigit(b & 0xF, 16)));
486484
}
487485
}
488486

489-
return builder.toString();
487+
return sb.toString();
490488
}
491489

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

0 commit comments

Comments
 (0)