Skip to content

Commit

Permalink
Merge pull request #27713 from mkouba/reactive-routes-base-empty-path
Browse files Browse the repository at this point in the history
Reactive routes - don't append trailing slash if empty path and base set
  • Loading branch information
geoand authored Sep 5, 2022
2 parents 05da186 + 8ceb51a commit e998d5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,11 @@ public boolean test(String name) {
}
} else {
// Path param set
if (!pathValue.asString().startsWith(SLASH)) {
String pathValueStr = pathValue.asString();
if (!pathValueStr.isEmpty() && !pathValueStr.startsWith(SLASH)) {
prefixed.append(SLASH);
}
prefixed.append(pathValue.asString());
prefixed.append(pathValueStr);
}
path = prefixed.toString();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class RouteBaseTest {
public void testPath() {
when().get("/hello").then().statusCode(200).body(is("Hello world!"));
when().get("/simple/hello").then().statusCode(200).body(is("Hello another world!"));
when().get("/simple").then().statusCode(200).body(is("Hello root!"));
when().get("/simple/").then().statusCode(200).body(is("Hello root!"));
when().get("/some/foo").then().statusCode(200).body(is("Hello foo!"));
}

Expand All @@ -34,7 +36,7 @@ public void testProduces() {
@RouteBase
static class SimpleBean {

@Route(path = "hello") // -> "/simple-bean/hello"
@Route(path = "hello") // -> "/hello"
void hello(RoutingContext context) {
context.response().end("Hello world!");
}
Expand All @@ -44,6 +46,11 @@ void hello(RoutingContext context) {
@RouteBase(path = "simple")
static class AnotherBean {

@Route(path = "") // -> "/simple"
void root(RoutingContext context) {
context.response().end("Hello root!");
}

@Route // path is derived from the method name -> "/simple/hello"
void hello(RoutingContext context) {
context.response().end("Hello another world!");
Expand Down

0 comments on commit e998d5a

Please sign in to comment.