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 2 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
42 changes: 24 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,30 @@ 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");
StringBuilder encoded = new StringBuilder();
for (char ch : ESCAPER.escape(str).toCharArray()) {
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();
balamurugana marked this conversation as resolved.
Show resolved Hide resolved
}

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