Merge branch '2.2.x'

Closes gh-20600
pull/20601/head
Stephane Nicoll 5 years ago
commit 70aa788747

@ -107,7 +107,7 @@ public final class WebFluxTags {
PathPattern pathPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (pathPattern != null) {
String patternString = pathPattern.getPatternString();
if (ignoreTrailingSlash) {
if (ignoreTrailingSlash && patternString.length() > 1) {
patternString = TRAILING_SLASH_PATTERN.matcher(patternString).replaceAll("");
}
return Tag.of("uri", patternString);

@ -112,7 +112,7 @@ public final class WebMvcTags {
if (request != null) {
String pattern = getMatchingPattern(request);
if (pattern != null) {
if (ignoreTrailingSlash) {
if (ignoreTrailingSlash && pattern.length() > 1) {
pattern = TRAILING_SLASH_PATTERN.matcher(pattern).replaceAll("");
}
return Tag.of("uri", pattern);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,12 +52,26 @@ class WebMvcTagsTests {
@Test
void uriTagValueIsBestMatchingPatternWhenAvailable() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring");
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/");
this.response.setStatus(301);
Tag tag = WebMvcTags.uri(this.request, this.response);
assertThat(tag.getValue()).isEqualTo("/spring/");
}
@Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring/");
Tag tag = WebMvcTags.uri(this.request, this.response, true);
assertThat(tag.getValue()).isEqualTo("/spring");
}
@Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashKeepSingleSlash() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/");
Tag tag = WebMvcTags.uri(this.request, this.response, true);
assertThat(tag.getValue()).isEqualTo("/");
}
@Test
void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() {
assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root");

@ -39,12 +39,13 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel
* @author Michael McFadyen
* @author Madhura Bhave
* @author Stephane Nicoll
*/
class WebFluxTagsTests {
private MockServerWebExchange exchange;
private PathPatternParser parser = new PathPatternParser();
private final PathPatternParser parser = new PathPatternParser();
@BeforeEach
void setup() {
@ -53,12 +54,28 @@ class WebFluxTagsTests {
@Test
void uriTagValueIsBestMatchingPatternWhenAvailable() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse("/spring"));
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
this.parser.parse("/spring/"));
this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY);
Tag tag = WebFluxTags.uri(this.exchange);
assertThat(tag.getValue()).isEqualTo("/spring/");
}
@Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashRemoveTrailingSlash() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE,
this.parser.parse("/spring/"));
Tag tag = WebFluxTags.uri(this.exchange, true);
assertThat(tag.getValue()).isEqualTo("/spring");
}
@Test
void uriTagValueWithBestMatchingPatternAndIgnoreTrailingSlashKeepSingleSlash() {
this.exchange.getAttributes().put(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, this.parser.parse("/"));
Tag tag = WebFluxTags.uri(this.exchange, true);
assertThat(tag.getValue()).isEqualTo("/");
}
@Test
void uriTagValueIsRedirectionWhenResponseStatusIs3xx() {
this.exchange.getResponse().setStatusCode(HttpStatus.MOVED_PERMANENTLY);

Loading…
Cancel
Save