From c79ac8ba1922b11c1b5f5d5d140c6b66aa3f74e6 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Wed, 17 Jan 2018 18:16:18 -0500 Subject: [PATCH] Remove / from prefix if present. Fixes #2625 --- .../cloud/netflix/zuul/filters/SimpleRouteLocator.java | 3 +++ .../netflix/zuul/filters/SimpleRouteLocatorTests.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java index 12f8e189..07fdfb97 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java @@ -138,6 +138,9 @@ public class SimpleRouteLocator implements RouteLocator, Ordered { } String targetPath = path; String prefix = this.properties.getPrefix(); + if(prefix.endsWith("/")) { + prefix = prefix.substring(0, prefix.length() - 1); + } if (path.startsWith(prefix + "/") && this.properties.isStripPrefix()) { targetPath = path.substring(prefix.length()); } diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java index 7519ebad..2f4ef1f0 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java @@ -69,6 +69,15 @@ public class SimpleRouteLocatorTests { assertEquals("/test/testservicea/**", locator.getRoutes().get(0).getFullPath()); } + @Test + public void testPrefix() { + ZuulProperties properties = new ZuulProperties(); + properties.setPrefix("/test/"); + RouteLocator locator = new FilteringRouteLocator("/", properties); + properties.getRoutes().put("testservicea", new ZuulRoute("/testservicea/**", "testservicea")); + assertEquals("/test/testservicea/**", locator.getRoutes().get(0).getFullPath()); + } + @Test public void test_getMatchingRouteFilterRouteAcceptor() { RouteLocator locator = new FilteringRouteLocator("/", this.zuul);