Bug fixes

This commit is contained in:
UnlegitDqrk
2026-02-27 20:31:10 +01:00
parent 5642869097
commit aa5963378d
8 changed files with 113 additions and 79 deletions

View File

@@ -7,6 +7,8 @@ import java.net.URI;
*/
public final class WebUrlUtil {
private static final String DEFAULT_DOCUMENT_PATH = "/index.html";
private WebUrlUtil() {
}
@@ -28,6 +30,25 @@ public final class WebUrlUtil {
}
}
/**
* Normalizes a request path for route/rule lookup.
*
* <p>Blank paths and "/" resolve to the default document.</p>
*
* @param path request path
* @return normalized absolute path
*/
public static String normalizeRequestPath(String path) {
if (path == null) return DEFAULT_DOCUMENT_PATH;
String p = path.trim();
if (p.isEmpty() || "/".equals(p)) {
return DEFAULT_DOCUMENT_PATH;
}
return p.startsWith("/") ? p : ("/" + p);
}
/**
* Normalizes a requested path to a content-root relative path.
*
@@ -39,12 +60,10 @@ public final class WebUrlUtil {
int q = p.indexOf('?');
if (q >= 0) p = p.substring(0, q);
if (p == null || p.isBlank() || "/".equals(p)) {
return "index.html";
}
p = normalizeRequestPath(p);
if (p.startsWith("/")) p = p.substring(1);
if (p.isBlank()) return "index.html";
return p;
}
}
}