From 51a17316ff5d464400ffc9f7a42b34ba0c0eea69 Mon Sep 17 00:00:00 2001 From: Erik van Paassen Date: Fri, 20 Aug 2021 17:09:57 +0200 Subject: [PATCH] Fix UrlPathHelper#shouldRemoveSemicolonContent() The checkReadOnly() method should only be called from methods that modify properties to prevent modification of read-only instances. Fixes #27256 --- .../java/org/springframework/web/util/UrlPathHelper.java | 1 - .../org/springframework/web/util/UrlPathHelperTests.java | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 575f822f957f..663dbb7566c4 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -147,7 +147,6 @@ public void setRemoveSemicolonContent(boolean removeSemicolonContent) { * Whether configured to remove ";" (semicolon) content from the request URI. */ public boolean shouldRemoveSemicolonContent() { - checkReadOnly(); return this.removeSemicolonContent; } diff --git a/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java b/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java index 0aea5a0b51d9..1b2921205f51 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UrlPathHelperTests.java @@ -22,6 +22,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; /** * Unit tests for {@link UrlPathHelper}. @@ -165,6 +166,11 @@ public void getLookupPathWithSemicolonContentAndNullPathInfo() { assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/welcome.html;c=d"); } + @Test // gh-27303 + public void shouldRemoveSemicolonContentWithReadOnlyInstance() { + assertThatCode(UrlPathHelper.defaultInstance::shouldRemoveSemicolonContent).doesNotThrowAnyException(); + } + // // suite of tests root requests for default servlets (SRV 11.2) on Websphere vs Tomcat and other containers