Commit 1d2d76b0 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.2.x'

Closes gh-21560
parents 18e0db63 afcb5d54
...@@ -110,6 +110,9 @@ public final class WebFluxTags { ...@@ -110,6 +110,9 @@ public final class WebFluxTags {
if (ignoreTrailingSlash && patternString.length() > 1) { if (ignoreTrailingSlash && patternString.length() > 1) {
patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll(""); patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll("");
} }
if (patternString.isEmpty()) {
return URI_ROOT;
}
return Tag.of("uri", patternString); return Tag.of("uri", patternString);
} }
HttpStatus status = exchange.getResponse().getStatusCode(); HttpStatus status = exchange.getResponse().getStatusCode();
......
...@@ -115,6 +115,9 @@ public final class WebMvcTags { ...@@ -115,6 +115,9 @@ public final class WebMvcTags {
if (ignoreTrailingSlash && pattern.length() > 1) { if (ignoreTrailingSlash && pattern.length() > 1) {
pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll(""); pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll("");
} }
if (pattern.isEmpty()) {
return URI_ROOT;
}
return Tag.of("uri", pattern); return Tag.of("uri", pattern);
} }
if (response != null) { if (response != null) {
......
...@@ -58,6 +58,14 @@ class WebMvcTagsTests { ...@@ -58,6 +58,14 @@ class WebMvcTagsTests {
assertThat(tag.getValue()).isEqualTo("/spring/"); assertThat(tag.getValue()).isEqualTo("/spring/");
} }
@Test
void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "");
this.response.setStatus(301);
Tag tag = WebMvcTags.uri(this.request, this.response);
assertThat(tag.getValue()).isEqualTo("root");
}
@Test @Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() { void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/"); this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/");
......
...@@ -61,6 +61,14 @@ class WebFluxTagsTests { ...@@ -61,6 +61,14 @@ class WebFluxTagsTests {
assertThat(tag.getValue()).isEqualTo("/spring/"); assertThat(tag.getValue()).isEqualTo("/spring/");
} }
@Test
void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse(""));
this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY);
Tag tag = WebFluxTags.uri(this.exchange);
assertThat(tag.getValue()).isEqualTo("root");
}
@Test @Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() { void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment