From 0acbda385e475b8045502a34204db47822416458 Mon Sep 17 00:00:00 2001 From: Jono Date: Thu, 5 Sep 2024 01:24:51 +1200 Subject: [PATCH] #42687 handle trailing slash --- .../server/mapping/RequestMapper.java | 27 ++++-- .../vertx/test/matching/RegexPathTest.java | 89 +++++++++++++++++++ 2 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/matching/RegexPathTest.java diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/RequestMapper.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/RequestMapper.java index 7fd7cb535f518..a6130273a0990 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/RequestMapper.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/mapping/RequestMapper.java @@ -76,14 +76,24 @@ private RequestMatch mapFromPathMatcher(String path, PathMatcher.PathMatch mapFromPathMatcher(String path, PathMatcher.PathMatch() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class) + .addClasses(EndingSlashTest.TestResource.class); + } + }); + + @Test + public void test() { + + get("/hello/world/1") + .then() + .statusCode(200) + .body(equalTo("Hello World! 1")); + + get("/hello/world/1/") + .then() + .statusCode(200) + .body(equalTo("Hello World! 1")); + + get("/hello/again/1") + .then() + .statusCode(200) + .body(equalTo("Hello Again! 1")); + + get("/hello/again/1/") + .then() + .statusCode(200) + .body(equalTo("Hello Again! 1")); + + get("/hello/again/2/surprise") + .then() + .statusCode(200) + .body(equalTo("Hello Surprise! 2")); + + get("/hello/again/2/surprise/") + .then() + .statusCode(200) + .body(equalTo("Hello Surprise! 2")); + } + + @Path("/hello") + public static class TestResource { + + @GET + @Path("/world/{sample}") + @Produces(MediaType.TEXT_PLAIN) + public String hello(int sample) { + return "Hello World! " + sample; + } + + @GET + @Path("/again/{sample:\\d+}") + @Produces(MediaType.TEXT_PLAIN) + public String helloWithRegex(int sample) { + return "Hello Again! " + sample; + } + + @GET + @Path("/again/{sample:\\d+}/surprise") + @Produces(MediaType.TEXT_PLAIN) + public String helloWithRegexSecond(int sample) { + return "Hello Surprise! " + sample; + } + } +}