Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize S3Escaper.encode() #1529

Merged
merged 3 commits into from
Feb 11, 2024
Merged
Changes from 1 commit
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
44 changes: 26 additions & 18 deletions api/src/main/java/io/minio/S3Escaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,32 @@ public static String encode(String str) {
return "";
}

return ESCAPER
.escape(str)
.replaceAll("\\!", "%21")
.replaceAll("\\$", "%24")
.replaceAll("\\&", "%26")
.replaceAll("\\'", "%27")
.replaceAll("\\(", "%28")
.replaceAll("\\)", "%29")
.replaceAll("\\*", "%2A")
.replaceAll("\\+", "%2B")
.replaceAll("\\,", "%2C")
.replaceAll("\\/", "%2F")
.replaceAll("\\:", "%3A")
.replaceAll("\\;", "%3B")
.replaceAll("\\=", "%3D")
.replaceAll("\\@", "%40")
.replaceAll("\\[", "%5B")
.replaceAll("\\]", "%5D");
str = ESCAPER.escape(str);
StringBuilder encoded = new StringBuilder(str.length() + Math.max(str.length() >> 3, 4));

for (char ch : str.toCharArray()) {
balamurugana marked this conversation as resolved.
Show resolved Hide resolved
switch (ch) {
case '!': encoded.append("%21"); break;
case '$': encoded.append("%24"); break;
case '&': encoded.append("%26"); break;
case '\'': encoded.append("%27"); break;
case '(': encoded.append("%28"); break;
case ')': encoded.append("%29"); break;
case '*': encoded.append("%2A"); break;
case '+': encoded.append("%2B"); break;
case ',': encoded.append("%2C"); break;
case '/': encoded.append("%2F"); break;
case ':': encoded.append("%3A"); break;
case ';': encoded.append("%3B"); break;
case '=': encoded.append("%3D"); break;
case '@': encoded.append("%40"); break;
case '[': encoded.append("%5B"); break;
case ']': encoded.append("%5D"); break;
default: encoded.append(ch);
}
}

return encoded.toString();
}

/** Returns S3 encoded string of given path where multiple '/' are trimmed. */
Expand Down
Loading