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

Additional tests for prefix paths and path params #2396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3595,4 +3595,54 @@ public void testPausedConnection4() {

await();
}

@Test
public void testPathPrefixWithPathParams() throws Exception {
router.route("/a/:id/b/:id2/c/*").handler(rc -> {
assertEquals("123", rc.pathParam("id"));
assertEquals("1234", rc.pathParam("id2"));
rc.response().end("r4");
});

router.route("/a/:id/b1/*").handler(rc -> {
assertEquals("123", rc.pathParam("id"));
rc.response().end("r3");
});

router.route("/a/:id/*").handler(rc -> {
assertEquals("123", rc.pathParam("id"));
rc.response().end("r2");
});

router.route("/:id/*").handler(rc -> {
assertEquals("123", rc.pathParam("id"));
rc.end("r1");
});

// should call "/:id/*"
testRequest(HttpMethod.GET, "/123/foo", 200, "OK", "r1");
testRequest(HttpMethod.GET, "/123/", 200, "OK", "r1");
// should call "/a/:id/*"
testRequest(HttpMethod.GET, "/a//123/", 200, "OK", "r2");
testRequest(HttpMethod.GET, "/a/123/foo/bar", 200, "OK", "r2");
// should call "/a/:id/b1/*"
testRequest(HttpMethod.GET, "/a//123/b1/", 200, "OK", "r3");
testRequest(HttpMethod.GET, "/a/123/b1/foo", 200, "OK", "r3");
// should call "/a/:id/b/:id2/c/*"
testRequest(HttpMethod.GET, "/a//123/b/1234/c/", 200, "OK", "r4");
testRequest(HttpMethod.GET, "/a/123/b/1234/c/foo", 200, "OK", "r4");


// should call "/:id/*"
testRequest(HttpMethod.GET, "/123", 200, "OK", "r1");
// should call "/a/:id/*"
testRequest(HttpMethod.GET, "/a/123", 200, "OK", "r2");
testRequest(HttpMethod.GET, "/a//123", 200, "OK", "r2");
// should call "/a/:id/b1/*"
testRequest(HttpMethod.GET, "/a/123/b1", 200, "OK", "r3");
testRequest(HttpMethod.GET, "/a//123//b1", 200, "OK", "r3");
// should call "/a/:id/b/:id2/c/*"
testRequest(HttpMethod.GET, "/a/123/b/1234/c", 200, "OK", "r4");
testRequest(HttpMethod.GET, "/a//123//b//1234//c", 200, "OK", "r4");
}
Comment on lines +3636 to +3647
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assumptions are incorrect according to the rules the matching engine works.

A wildcard route is a route that ends with: * however it is important to note that the final slash is significant. At the HTTP spec level: http://server/a and http://server/a/ are considered 2 different resources. In vertx-web we claim that for simplicity, a static route that doesn't include the final / will match both requests to the same route, however, the routes in this example end with /* which means that the final / is significative. This means the request must include it to be matched.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks alot for the explanation! There might still be some inconsistencies in documentation and/or behavior - see also #2395 (comment)

}