Skip to content

Commit

Permalink
Merge branch '2.2.x' into 2.3.x
Browse files Browse the repository at this point in the history
Closes gh-24193
  • Loading branch information
snicoll committed Nov 18, 2020
2 parents af8b6ed + d96ff16 commit 76912d1
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -49,7 +49,7 @@ public final class WebFluxTags {

private static final Tag EXCEPTION_NONE = Tag.of("exception", "None");

private static final Pattern TRAILING_SLASH_PATTERN = Pattern.compile("/$");
private static final Pattern FORWARD_SLASHES_PATTERN = Pattern.compile("//+");

private WebFluxTags() {
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public static Tag uri(ServerWebExchange exchange, boolean ignoreTrailingSlash) {
if (pathPattern != null) {
String patternString = pathPattern.getPatternString();
if (ignoreTrailingSlash && patternString.length() > 1) {
patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll("");
patternString = removeTrailingSlash(patternString);
}
if (patternString.isEmpty()) {
return URI_ROOT;
Expand All @@ -134,7 +134,15 @@ public static Tag uri(ServerWebExchange exchange, boolean ignoreTrailingSlash) {
private static String getPathInfo(ServerWebExchange exchange) {
String path = exchange.getRequest().getPath().value();
String uri = StringUtils.hasText(path) ? path : "/";
return uri.replaceAll("//+", "/").replaceAll("/$", "");
String singleSlashes = FORWARD_SLASHES_PATTERN.matcher(uri).replaceAll("/");
return removeTrailingSlash(singleSlashes);
}

private static String removeTrailingSlash(String text) {
if (!StringUtils.hasLength(text)) {
return text;
}
return text.endsWith("/") ? text.substring(0, text.length() - 1) : text;
}

/**
Expand Down

0 comments on commit 76912d1

Please sign in to comment.