mirror of https://github.com/apache/jclouds.git
Handle nested braces in UriTemplates.expand
This allows replacement of JSON-like payloads without using hacks like percent-encoding braces.
This commit is contained in:
parent
f46b38dd89
commit
981b882f59
|
@ -44,17 +44,26 @@ public class UriTemplates {
|
|||
for (char c : Lists.charactersOf(template)) {
|
||||
switch (c) {
|
||||
case '{':
|
||||
if (inVar) {
|
||||
builder.append('{');
|
||||
builder.append(var);
|
||||
var.setLength(0);
|
||||
}
|
||||
inVar = true;
|
||||
break;
|
||||
case '}':
|
||||
inVar = false;
|
||||
String key = var.toString();
|
||||
Object value = variables.get(var.toString());
|
||||
if (value != null)
|
||||
builder.append(value);
|
||||
else
|
||||
builder.append('{').append(key).append('}');
|
||||
if (inVar) {
|
||||
if (value != null)
|
||||
builder.append(value);
|
||||
else
|
||||
builder.append('{').append(key).append('}');
|
||||
} else {
|
||||
builder.append('}');
|
||||
}
|
||||
var.setLength(0);
|
||||
inVar = false;
|
||||
break;
|
||||
default:
|
||||
if (inVar)
|
||||
|
|
|
@ -51,4 +51,8 @@ public class UriTemplatesTest {
|
|||
public void testMissingParamProceeds() {
|
||||
assertEquals(expand("/{user-dir}", ImmutableMap.of("user_dir", "foo")), "/{user-dir}");
|
||||
}
|
||||
|
||||
public void testJson() {
|
||||
assertEquals(expand("{\"key\":\"{variable}\"}", ImmutableMap.of("variable", "value")), "{\"key\":\"value\"}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue