Skip to content

Commit

Permalink
Merge branch '2.2.x'
Browse files Browse the repository at this point in the history
Closes gh-21560
  • Loading branch information
snicoll committed May 25, 2020
2 parents 18e0db6 + afcb5d5 commit 1d2d76b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static Tag uri(ServerWebExchange exchange, boolean ignoreTrailingSlash) {
if (ignoreTrailingSlash && patternString.length() > 1) {
patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll("");
}
if (patternString.isEmpty()) {
return URI_ROOT;
}
return Tag.of("uri", patternString);
}
HttpStatus status = exchange.getResponse().getStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public static Tag uri(HttpServletRequest request, HttpServletResponse response,
if (ignoreTrailingSlash && pattern.length() > 1) {
pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll("");
}
if (pattern.isEmpty()) {
return URI_ROOT;
}
return Tag.of("uri", pattern);
}
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() {
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
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() {
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
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
Expand Down

0 comments on commit 1d2d76b

Please sign in to comment.