Skip to content

Commit 1d2d76b

Browse files
committed
Merge branch '2.2.x'
Closes gh-21560
2 parents 18e0db6 + afcb5d5 commit 1d2d76b

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public static Tag uri(ServerWebExchange exchange, boolean ignoreTrailingSlash) {
110110
if (ignoreTrailingSlash && patternString.length() > 1) {
111111
patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll("");
112112
}
113+
if (patternString.isEmpty()) {
114+
return URI_ROOT;
115+
}
113116
return Tag.of("uri", patternString);
114117
}
115118
HttpStatus status = exchange.getResponse().getStatusCode();

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public static Tag uri(HttpServletRequest request, HttpServletResponse response,
115115
if (ignoreTrailingSlash && pattern.length() > 1) {
116116
pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll("");
117117
}
118+
if (pattern.isEmpty()) {
119+
return URI_ROOT;
120+
}
118121
return Tag.of("uri", pattern);
119122
}
120123
if (response != null) {

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() {
5858
assertThat(tag.getValue()).isEqualTo("/spring/");
5959
}
6060

61+
@Test
62+
void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() {
63+
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "");
64+
this.response.setStatus(301);
65+
Tag tag = WebMvcTags.uri(this.request, this.response);
66+
assertThat(tag.getValue()).isEqualTo("root");
67+
}
68+
6169
@Test
6270
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
6371
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/");

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ void uriTagValueIsBestMatchingPatternWhenAvailable() {
6161
assertThat(tag.getValue()).isEqualTo("/spring/");
6262
}
6363

64+
@Test
65+
void uriTagValueIsRootWhenBestMatchingPatternIsEmpty() {
66+
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse(""));
67+
this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY);
68+
Tag tag = WebFluxTags.uri(this.exchange);
69+
assertThat(tag.getValue()).isEqualTo("root");
70+
}
71+
6472
@Test
6573
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
6674
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,

0 commit comments

Comments
 (0)