Skip to content

Commit

Permalink
Decode path param in path param extractor
Browse files Browse the repository at this point in the history
Fixes quarkusio#35960

Signed-off-by: rmartinc <[email protected]>
  • Loading branch information
rmartinc committed Dec 4, 2023
1 parent 574e4f5 commit 09c8d4d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jboss.resteasy.reactive.server.core.parameters;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.jboss.resteasy.reactive.common.util.Encode;
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
Expand All @@ -20,13 +22,13 @@ public PathParamExtractor(int index, boolean encoded, boolean single) {
@Override
public Object extractParameter(ResteasyReactiveRequestContext context) {
String pathParam = context.getPathParam(index);
if (encoded) {
pathParam = Encode.encodeQueryParam(pathParam);
}
if (single) {
return pathParam;
return encoded ? pathParam : Encode.decodePath(pathParam);
} else {
return List.of(pathParam.split("/"));
return encoded
? List.of(pathParam.split("/"))
: Arrays.stream(pathParam.split("/")).map(Encode::decodePath)
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.Map;
import java.util.regex.Matcher;

import org.jboss.resteasy.reactive.common.util.URIDecoder;

public class RequestMapper<T> {

private static final String[] EMPTY_STRING_ARRAY = new String[0];
Expand Down Expand Up @@ -111,7 +109,7 @@ private RequestMatch<T> mapFromPathMatcher(String path, PathMatcher.PathMatch<Ar
while (matchPos < pathLength && path.charAt(matchPos) != '/') {
matchPos++;
}
params[paramCount++] = URIDecoder.decodeURIComponent(path.substring(start, matchPos), false);
params[paramCount++] = path.substring(start, matchPos);
}
}
if (!matched) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public void testLiteralInRegex() {
.then()
.statusCode(200)
.body(equalTo("plain:abb/foo/alongpathtotriggerbug"));
RestAssured.get("/regex/abb/foo/path space")
.then()
.statusCode(200)
.body(equalTo("plain:abb/foo/path space"));
RestAssured.get("/regex/abb/literal/ddc")
.then()
.statusCode(200)
Expand Down

0 comments on commit 09c8d4d

Please sign in to comment.