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 path segment handling of encoded values #34809

Merged
merged 1 commit into from
Jul 18, 2023
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 @@ -85,7 +85,7 @@ private RequestMatch<T> mapFromPathMatcher(String path, PathMatcher.PathMatch<Ar
}
matchPos = matcher.end();
for (String group : segment.groups) {
params[paramCount++] = URIDecoder.decodeURIComponent(matcher.group(group), false);
params[paramCount++] = matcher.group(group);
}
} else if (segment.type == URITemplate.Type.LITERAL) {
//make sure the literal text is the same
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.jboss.resteasy.reactive.server.vertx.test.matching;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import java.util.List;
import java.util.function.Supplier;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.PathSegment;

import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class PathSegmentTest {

@RegisterExtension
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(Resource.class);
}
});

@Test
public void testRegularMatch() {
given()
.when().get("/test/list/{seg1}/{seg2}", "key1", "key2")
.then()
.statusCode(200)
.body(is("Path(2): [key1, key2]"));
}

@Test
public void testEncodedPath() {
given()
.when().get("/test/list/{seg1}/{seg2}", "key/1", "key/2")
.then()
.statusCode(200)
.body(is("Path(2): [key/1, key/2]"));
}

@Path("/test")
public static class Resource {
@GET
@Path("/list/{primaryKey: .+}")
public String pathAsList(@PathParam("primaryKey") List<PathSegment> path) {
return String.format("Path(%d): %s", path.size(), path);
}
}
}