mirror of https://github.com/apache/jclouds.git
[JCLOUDS-1433] $ and \ in tokenValues passed to Strings2.replaceTokens(String, Multimap) could result in IllegalArgumentException.
This commit is contained in:
parent
1bd3b8f9df
commit
c34935dcd3
|
@ -182,7 +182,7 @@ public class Strings2 {
|
||||||
public static String replaceTokens(String input, Multimap<String, ?> tokenValues) {
|
public static String replaceTokens(String input, Multimap<String, ?> tokenValues) {
|
||||||
for (Entry<String, ?> tokenValue : tokenValues.entries()) {
|
for (Entry<String, ?> tokenValue : tokenValues.entries()) {
|
||||||
Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey());
|
Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey());
|
||||||
input = pattern.matcher(input).replaceAll(tokenValue.getValue().toString());
|
input = pattern.matcher(input).replaceAll(tokenValue.getValue().toString().replace("\\", "\\\\").replace("$", "\\$"));
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,15 @@ import static org.testng.Assert.assertEquals;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class Strings2Test {
|
public class Strings2Test {
|
||||||
|
|
||||||
public void testReplaceTokens() {
|
public void testReplaceTokens() {
|
||||||
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMap.of("where", "world")), "hello world");
|
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMap.of("where", "world")), "hello world");
|
||||||
|
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMap.of("where", "$1,000,000 \\o/!")), "hello $1,000,000 \\o/!");
|
||||||
|
assertEquals(Strings2.replaceTokens("hello {where}", ImmutableMultimap.of("where", "$1,000,000 \\o/!")), "hello $1,000,000 \\o/!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUrlEncodeDecodeShouldGiveTheSameString() {
|
public void testUrlEncodeDecodeShouldGiveTheSameString() {
|
||||||
|
|
Loading…
Reference in New Issue