Skip to content

Commit

Permalink
Fix path segment handling of encoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Jul 18, 2023
1 parent 4dee32e commit c2285ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
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);
}
}
}

0 comments on commit c2285ec

Please sign in to comment.