Skip to content

Commit

Permalink
Fix issue with RR form decoding
Browse files Browse the repository at this point in the history
Fixes quarkusio#23055

(cherry picked from commit 41f2d20)
  • Loading branch information
stuartwdouglas authored and gsmet committed Jan 25, 2022
1 parent bdd4cf1 commit 1d2ecd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
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

0 comments on commit 1d2ecd6

Please sign in to comment.