From 7018804e8451fa935e8715754de43a3ef62fa5c8 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 13 Jun 2017 15:09:22 +0200 Subject: [PATCH] ServerRequest.path() should return raw path After this commit, ServerRequest.path() returns the raw, unencoded path, as that is expected by the PathPatternParser. --- .../web/reactive/function/server/ServerRequest.java | 2 +- .../function/server/RequestPredicatesTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java index 3a2022f004..15e5fc17ea 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java @@ -67,7 +67,7 @@ public interface ServerRequest { * Return the request path. */ default String path() { - return uri().getPath(); + return uri().getRawPath(); } /** diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java index 3a535f9b6d..10a04e3943 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RequestPredicatesTests.java @@ -95,6 +95,17 @@ public class RequestPredicatesTests { assertFalse(predicate.test(request)); } + @Test + public void pathEncoded() throws Exception { + URI uri = URI.create("http://localhost/foo%20bar"); + RequestPredicate predicate = RequestPredicates.path("/foo bar"); + MockServerRequest request = MockServerRequest.builder().uri(uri).build(); + assertTrue(predicate.test(request)); + + request = MockServerRequest.builder().build(); + assertFalse(predicate.test(request)); + } + @Test public void pathPredicates() throws Exception { PathPatternParser parser = new PathPatternParser();