Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in string split #2146

Merged
merged 5 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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