Skip to content

Commit

Permalink
Fix bug in string split (#2146)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
arthurscchan authored Aug 8, 2023
1 parent fc6bf6f commit b46ad26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/feign/template/Expressions.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public static Expression create(final String value) {
/* 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];
}
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/feign/template/ExpressionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ public void simpleExpression() {
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) + "}";
Expand Down

0 comments on commit b46ad26

Please sign in to comment.