Skip to content

Commit

Permalink
JCLOUDS-1630: Handle URI template properly with opened curve bracket (#…
Browse files Browse the repository at this point in the history
…199)

Co-authored-by: Maksim_Hadalau <Maksim_Hadalau@epam.com>
  • Loading branch information
Maxim-Gadalov and Maksim_Hadalau committed Mar 20, 2024
1 parent b379c17 commit bc43572
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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");
}
}

0 comments on commit bc43572

Please sign in to comment.