diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/KeyValueConverter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/KeyValueConverter.java index cc57f4b2..5aa1f9b8 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/KeyValueConverter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/KeyValueConverter.java @@ -27,19 +27,19 @@ import org.springframework.util.StringUtils; @Deprecated public class KeyValueConverter implements Converter { - private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value'"; + private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value', received: "; @Override public KeyValue convert(String source) throws IllegalArgumentException { try { String[] split = source.split(":"); - if (source.contains(":") && StringUtils.hasText(split[0])) { + if (split.length == 2) { return new KeyValue(split[0], split.length == 1 ? "" : split[1]); } - throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE); + throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source); } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE); + throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source); } } diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/config/KeyValueConverter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/config/KeyValueConverter.java index a2101aa2..d7a9e84e 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/config/KeyValueConverter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/config/KeyValueConverter.java @@ -24,19 +24,19 @@ import org.springframework.util.StringUtils; */ public class KeyValueConverter implements Converter { - private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value'"; + private static final String INVALID_CONFIGURATION_MESSAGE = "Invalid configuration, expected format is: 'key:value', received: "; @Override public KeyValue convert(String source) throws IllegalArgumentException { try { String[] split = source.split(":"); - if (source.contains(":") && StringUtils.hasText(split[0])) { + if (split.length == 2) { return new KeyValue(split[0], split.length == 1 ? "" : split[1]); } - throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE); + throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source); } catch (ArrayIndexOutOfBoundsException e) { - throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE); + throw new IllegalArgumentException(INVALID_CONFIGURATION_MESSAGE + source); } } diff --git a/spring-cloud-gateway-server/src/test/resources/application-request-headers-if-not-present-web-filter.yml b/spring-cloud-gateway-server/src/test/resources/application-request-headers-if-not-present-web-filter.yml index f75cf269..23a88f20 100644 --- a/spring-cloud-gateway-server/src/test/resources/application-request-headers-if-not-present-web-filter.yml +++ b/spring-cloud-gateway-server/src/test/resources/application-request-headers-if-not-present-web-filter.yml @@ -14,4 +14,4 @@ spring: - Path=/multivalueheaders filters: - AddRequestHeadersIfNotPresent=X-Request-Example:ValueA,X-Request-Second-Example:ValueC - - AddRequestHeadersIfNotPresent=X-Request-Example:ValueB,X-Request-Second-Example:ValueD + - AddRequestHeadersIfNotPresent=X-Request-Example:ValueB, X-Request-Second-Example:ValueD