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

Improve UriComponents.sanitizeSource() #25401

Merged
merged 1 commit into from Aug 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -276,7 +276,8 @@ static String expandUriComponent(@Nullable String source, UriTemplateVariables u
*/
private static String sanitizeSource(String source) {
int level = 0;
StringBuilder sb = new StringBuilder();
int lastCharIndex = 0;
char[] chars = new char[source.length()];
for (char c : source.toCharArray()) {
if (c == '{') {
level++;
Expand All @@ -287,9 +288,9 @@ private static String sanitizeSource(String source) {
if (level > 1 || (level == 1 && c == '}')) {
continue;
}
sb.append(c);
chars[lastCharIndex++] = c;
}
return sb.toString();
return new String(chars, 0, lastCharIndex);
}

private static String getVariableName(String match) {
Expand Down