Skip to content

Commit 7018804

Browse files
committed
ServerRequest.path() should return raw path
After this commit, ServerRequest.path() returns the raw, unencoded path, as that is expected by the PathPatternParser.
1 parent 97909f2 commit 7018804

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public interface ServerRequest {
6767
* Return the request path.
6868
*/
6969
default String path() {
70-
return uri().getPath();
70+
return uri().getRawPath();
7171
}
7272

7373
/**

spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ public void path() throws Exception {
9595
assertFalse(predicate.test(request));
9696
}
9797

98+
@Test
99+
public void pathEncoded() throws Exception {
100+
URI uri = URI.create("http://localhost/foo%20bar");
101+
RequestPredicate predicate = RequestPredicates.path("/foo bar");
102+
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
103+
assertTrue(predicate.test(request));
104+
105+
request = MockServerRequest.builder().build();
106+
assertFalse(predicate.test(request));
107+
}
108+
98109
@Test
99110
public void pathPredicates() throws Exception {
100111
PathPatternParser parser = new PathPatternParser();

0 commit comments

Comments
 (0)