From 0d3a5d210ac766733ba40bfccd177a76368e6669 Mon Sep 17 00:00:00 2001 From: coehgns Date: Thu, 12 Feb 2026 11:13:02 +0900 Subject: [PATCH] Add tests for PathPatternRequestMatcher path caching Verify parsed request path is cleared when matcher parses it, and preserved when already present. Signed-off-by: coehgns --- .../PathPatternRequestMatcherTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/web/src/test/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcherTests.java b/web/src/test/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcherTests.java index a854e79d06..4e21e7a0e5 100644 --- a/web/src/test/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcherTests.java +++ b/web/src/test/java/org/springframework/security/web/servlet/util/matcher/PathPatternRequestMatcherTests.java @@ -154,6 +154,25 @@ public class PathPatternRequestMatcherTests { assertThat(matcher.matches(mock)).isFalse(); } + @Test + void matcherWhenRequestPathNotParsedThenDoesNotLeaveParsedRequestPath() { + RequestMatcher matcher = pathPattern("/uri"); + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/uri"); + assertThat(ServletRequestPathUtils.hasParsedRequestPath(request)).isFalse(); + assertThat(matcher.matches(request)).isTrue(); + assertThat(ServletRequestPathUtils.hasParsedRequestPath(request)).isFalse(); + } + + @Test + void matcherWhenRequestPathAlreadyParsedThenLeavesParsedRequestPath() { + RequestMatcher matcher = pathPattern("/uri"); + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/uri"); + ServletRequestPathUtils.parseAndCache(request); + assertThat(ServletRequestPathUtils.hasParsedRequestPath(request)).isTrue(); + assertThat(matcher.matches(request)).isTrue(); + assertThat(ServletRequestPathUtils.hasParsedRequestPath(request)).isTrue(); + } + MockHttpServletRequest request(String uri) { MockHttpServletRequest request = new MockHttpServletRequest("GET", uri); ServletRequestPathUtils.parseAndCache(request);