Browse Source

Checks for null value if query parameter does not have a value

fixes gh-423
pull/427/head
Spencer Gibb 6 years ago
parent
commit
c343b0ceec
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactory.java
  2. 10
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactory.java

@ -58,7 +58,7 @@ public class QueryRoutePredicateFactory extends AbstractRoutePredicateFactory<Qu @@ -58,7 +58,7 @@ public class QueryRoutePredicateFactory extends AbstractRoutePredicateFactory<Qu
return false;
}
for (String value : values) {
if (value.matches(config.regexp)) {
if (value != null && value.matches(config.regexp)) {
return true;
}
}

10
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java

@ -64,6 +64,16 @@ public class QueryRoutePredicateFactoryTests extends BaseWebClientTests { @@ -64,6 +64,16 @@ public class QueryRoutePredicateFactoryTests extends BaseWebClientTests {
.expectHeader().valueEquals(ROUTE_ID_HEADER, "foo_query_param");;
}
@Test
public void emptyQueryParamWorks() {
testClient.get().uri("/get?foo")
.exchange()
.expectStatus().isOk()
.expectHeader().valueEquals(ROUTE_ID_HEADER, "default_path_to_httpbin");;
output.expect(not(containsString("Error applying predicate for route: foo_query_param")));
}
@EnableAutoConfiguration
@SpringBootConfiguration
@Import(DefaultTestConfig.class)

Loading…
Cancel
Save