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

Fix issue with RR form decoding #23160

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class FormParamTest {
@Test
void shouldPassFormParam() {
FormClient formClient = RestClientBuilder.newBuilder().baseUri(baseUri).build(FormClient.class);
String result = formClient.directForm("par1", "par2");
assertThat(result).isEqualTo("root formParam1:par1,formParam2:par2");
String result = formClient.directForm("par1", "par 2");
assertThat(result).isEqualTo("root formParam1:par1,formParam2:par 2");
}

@Test
void shouldPassFormParamFromSubResource() {
FormClient formClient = RestClientBuilder.newBuilder().baseUri(baseUri).build(FormClient.class);
String result = formClient.subForm("par1", "par2").form("spar1", "spar2");
assertThat(result).isEqualTo("sub rootParam1:par1,rootParam2:par2,subParam1:spar1,subParam2:spar2");
String result = formClient.subForm("par1", "par 2").form("spar1", "spar 2");
assertThat(result).isEqualTo("sub rootParam1:par1,rootParam2:par 2,subParam1:spar1,subParam2:spar 2");
}

public interface FormClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,13 @@ public static String decode(String s, Charset enc, boolean decodeSlash, boolean
if (buffer != null) {
buffer.setLength(0);
}
boolean needToChange = false;
int numChars = s.length();
int i = 0;
while (i < numChars) {
char c = s.charAt(i);
if (c == '+') {
if (formEncoding) {
if (!needToChange) {
if (buffer == null) {
buffer = new StringBuilder();
}
buffer.append(s, 0, i);
}
buffer.append(' ');
i++;
} else {
i++;
if (needToChange) {
buffer.append(c);
}
}
} else if (c == '%' || c > 127) {
if (!needToChange) {
if (buffer == null) {
buffer = new StringBuilder();
}
buffer.append(s, 0, i);
needToChange = true;
}
if (c == '%' || c > 127 || c == '+') {
buffer = new StringBuilder();
buffer.append(s, 0, i);
/*
* Starting with this instance of a character
* that needs to be encoded, process all
Expand Down Expand Up @@ -232,16 +210,16 @@ public static String decode(String s, Charset enc, boolean decodeSlash, boolean

String decoded = new String(bytes, 0, pos, enc);
buffer.append(decoded);
return buffer.toString();
} catch (NumberFormatException e) {
throw failedToDecodeURL(s, enc, e);
}
break;
} else {
i++;
}
}

return (needToChange ? buffer.toString() : s);
return s;
}

private static RuntimeException failedToDecodeURL(String s, Charset enc, Throwable o) {
Expand Down