Skip to content

Commit 8a3dd33

Browse files
committed
Fix attempt for double url decoding issue.
1 parent 042bec0 commit 8a3dd33

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎jooby/src/main/java/io/jooby/internal/FormdataNode.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,4 @@ public class FormdataNode extends HashValue implements Formdata {
1212
public FormdataNode(Context ctx) {
1313
super(ctx, null);
1414
}
15-
16-
@Override protected String decode(String value) {
17-
return UrlParser.decode(value, false);
18-
}
1915
}

‎jooby/src/main/java/io/jooby/internal/UrlParser.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@ public static QueryString queryString(Context ctx, String queryString) {
3030
}
3131

3232
public static String decodePathSegment(String value) {
33-
return decode(value, true);
34-
}
35-
36-
public static String decode(String value, boolean isPath) {
3733
if (value == null || value.length() == 0) {
3834
return "";
3935
}
40-
return decodeComponent(value, 0, value.length(), StandardCharsets.UTF_8, isPath);
36+
return decodeComponent(value, 0, value.length(), StandardCharsets.UTF_8, true);
4137
}
4238

4339
private static void decodeParams(HashValue root, String s, int from, Charset charset,

‎tests/src/test/java/io/jooby/FeaturedTest.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,16 +2999,33 @@ public void rawVsDecodedValues(ServerTestRunner runner) {
29992999
assertEquals("a b/", rsp.body().string().trim());
30003000
});
30013001

3002+
// put in encoded value, expect urldecode(value)
30023003
client.post("/form", new FormBody.Builder()
3003-
.add("v", "a+b%2f")
3004+
.addEncoded("v", "a+b%2f")
30043005
.build(), rsp -> {
30053006
assertEquals("a b/", rsp.body().string());
30063007
});
30073008

3009+
// put in "raw" value, expect it as it is
3010+
client.post("/form", new FormBody.Builder()
3011+
.add("v", "a+b%2f")
3012+
.build(), rsp -> {
3013+
assertEquals("a+b%2f", rsp.body().string());
3014+
});
3015+
3016+
// no coding is done, expect it as it is
30083017
client.post("/multipart", new MultipartBody.Builder()
30093018
.setType(MultipartBody.FORM)
30103019
.addFormDataPart("v", "a+b%2f")
30113020
.build(), rsp -> {
3021+
assertEquals("a+b%2f", rsp.body().string());
3022+
});
3023+
3024+
// no coding is done, expect it as it is
3025+
client.post("/multipart", new MultipartBody.Builder()
3026+
.setType(MultipartBody.FORM)
3027+
.addFormDataPart("v", "a b/")
3028+
.build(), rsp -> {
30123029
assertEquals("a b/", rsp.body().string());
30133030
});
30143031
});

0 commit comments

Comments
 (0)