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

Possible to handle routes for base URI without path from extensions #42896

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
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
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
Loading