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

JCLOUDS-1630: Handle URI template properly with opened curve bracket #199

Merged
merged 1 commit into from
Mar 20, 2024
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
11 changes: 11 additions & 0 deletions core/src/main/java/org/jclouds/http/UriTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static String expand(String template, Map<String, ?> variables) {
return template.toString(); // skip expansion if there's no valid variables set. ex. {a} is the first valid
checkNotNull(variables, "variables for %s", template);

// if no variables provided - return template as is
if (variables.isEmpty()) {
return template;
}

boolean inVar = false;
StringBuilder var = new StringBuilder();
StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -72,6 +77,12 @@ public static String expand(String template, Map<String, ?> variables) {
builder.append(c);
}
}

// if variables provided but, curve bracket is not closed - append remaining to the result
if (inVar) {
builder.append('{').append(var);
}

return builder.toString();
}
}
7 changes: 7 additions & 0 deletions core/src/test/java/org/jclouds/http/UriTemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ public void testMissingParamProceeds() {
public void testJson() {
assertEquals(expand("{\"key\":\"{variable}\"}", ImmutableMap.of("variable", "value")), "{\"key\":\"value\"}");
}

public void testExpandWithOpenedCurveBracket() {
assertEquals(expand("/repos/folder with { brackets in a key", ImmutableMap.of()),
"/repos/folder with { brackets in a key");
assertEquals(expand("/repos/folder with {foo", ImmutableMap.of("foo", "var")),
"/repos/folder with {foo");
}
}
Loading