mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #21392 from jkschneider
* pr/21392: Fix uri tag for empty path Closes gh-21392
This commit is contained in:
commit
3f372824ea
@ -110,6 +110,9 @@ public final class WebFluxTags {
|
||||
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();
|
||||
|
@ -115,6 +115,9 @@ public final class WebMvcTags {
|
||||
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) {
|
||||
|
@ -58,6 +58,14 @@ class WebMvcTagsTests {
|
||||
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/");
|
||||
|
@ -61,6 +61,15 @@ class WebFluxTagsTests {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user