Skip to content

Commit

Permalink
[Vert.X] Possible to handle routes for base URI without path from ext…
Browse files Browse the repository at this point in the history
…ensions

Closes #42840

Signed-off-by: Martin Bartoš <[email protected]>
  • Loading branch information
mabartos committed Aug 30, 2024
1 parent 662cf29 commit c4beb8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public String getRootPath() {
* <ul>
* <li>{@code resolvePath("foo")} will return {@literal /foo}</li>
* <li>{@code resolvePath("/foo")} will return {@literal /foo}</li>
* <li>{@code resolvePath("/")} will return {@literal /}</li>
* </ul>
* Given {@literal quarkus.http.root-path=/app}
* <ul>
* <li>{@code resolvePath("foo")} will return {@literal /app/foo}</li>
* <li>{@code resolvePath("/foo")} will return {@literal /foo}</li>
* <li>{@code resolvePath("/")} will return {@literal /}</li>
* </ul>
* <p>
* The returned path will not end with a slash.
Expand All @@ -64,7 +66,8 @@ public String getRootPath() {
* @see UriNormalizationUtil#normalizeWithBase(URI, String, boolean)
*/
public String resolvePath(String path) {
return UriNormalizationUtil.normalizeWithBase(rootPath, path, false).getPath();
var isSlashAbsolutePath = "/".equals(path);
return UriNormalizationUtil.normalizeWithBase(rootPath, path, isSlashAbsolutePath).getPath();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void testResolvePathWithSlash() {
HttpRootPathBuildItem buildItem = new HttpRootPathBuildItem("/");

Assertions.assertEquals("/", buildItem.resolvePath(""));
Assertions.assertEquals("/", buildItem.resolvePath("/"));
Assertions.assertEquals("/foo", buildItem.resolvePath("foo"));
Assertions.assertEquals("/foo", buildItem.resolvePath("/foo"));
Assertions.assertThrows(IllegalArgumentException.class, () -> buildItem.resolvePath("../foo"));
Expand All @@ -19,6 +20,7 @@ void testResolvePathWithSlashApp() {
HttpRootPathBuildItem buildItem = new HttpRootPathBuildItem("/app");

Assertions.assertEquals("/app", buildItem.resolvePath(""));
Assertions.assertEquals("/", buildItem.resolvePath("/"));
Assertions.assertEquals("/app/foo", buildItem.resolvePath("foo"));
Assertions.assertEquals("/foo", buildItem.resolvePath("/foo"));
}
Expand Down

0 comments on commit c4beb8c

Please sign in to comment.