Browse Source

Only strip the prefix if it actually part of the path. Fixes #2377 (#2624)

pull/6/head
Ryan Baxter 7 years ago committed by GitHub
parent
commit
d2155dc561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java
  2. 11
      spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java

2
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocator.java

@ -138,7 +138,7 @@ public class SimpleRouteLocator implements RouteLocator, Ordered { @@ -138,7 +138,7 @@ public class SimpleRouteLocator implements RouteLocator, Ordered {
}
String targetPath = path;
String prefix = this.properties.getPrefix();
if (path.startsWith(prefix) && this.properties.isStripPrefix()) {
if (path.startsWith(prefix + "/") && this.properties.isStripPrefix()) {
targetPath = path.substring(prefix.length());
}
if (route.isStripPrefix()) {

11
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/SimpleRouteLocatorTests.java

@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.hasItem; @@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
@ -58,6 +59,16 @@ public class SimpleRouteLocatorTests { @@ -58,6 +59,16 @@ public class SimpleRouteLocatorTests {
assertThat(routes, hasSize(1));
}
@Test
public void testStripPrefix() {
ZuulProperties properties = new ZuulProperties();
properties.setPrefix("/test");
properties.setStripPrefix(true);
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);

Loading…
Cancel
Save