Browse Source

Fix bug in string split (#2146)

* Fix empty split bug

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

* Add unit testing

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

* Fix formatting

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

---------

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
pull/2151/head
Arthur Chan 1 year ago committed by GitHub
parent
commit
b46ad26752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      core/src/main/java/feign/template/Expressions.java
  2. 13
      core/src/test/java/feign/template/ExpressionsTest.java

4
core/src/main/java/feign/template/Expressions.java

@ -88,8 +88,8 @@ public final class Expressions { @@ -88,8 +88,8 @@ public final class Expressions {
/* we have a valid variable expression, extract the name from the first group */
variableName = matcher.group(3).trim();
if (variableName.contains(":")) {
/* split on the colon */
String[] parts = variableName.split(":");
/* split on the colon and ensure the size of parts array must be 2 */
String[] parts = variableName.split(":", 2);
variableName = parts[0];
variablePattern = parts[1];
}

13
core/src/test/java/feign/template/ExpressionsTest.java

@ -28,6 +28,19 @@ public class ExpressionsTest { @@ -28,6 +28,19 @@ public class ExpressionsTest {
assertThat(expanded).isEqualToIgnoringCase("foo=bar");
}
@Test
public void malformedExpression() {
String[] malformedStrings = {"{:}", "{str1:}", "{str1:{:}", "{str1:{str2:}"};
for (String malformed : malformedStrings) {
try {
Expressions.create(malformed);
} catch (Exception e) {
assertThatObject(e).isNotInstanceOf(ArrayIndexOutOfBoundsException.class);
}
}
}
@Test
public void malformedBodyTemplate() {
String bodyTemplate = "{" + "a".repeat(65536) + "}";

Loading…
Cancel
Save