mirror of
https://github.com/apache/jclouds.git
synced 2025-02-07 10:39:03 +00:00
[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) {
|
||||
for (Entry<String, ?> tokenValue : tokenValues.entries()) {
|
||||
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;
|
||||
}
|
||||
|
@ -23,12 +23,15 @@ import static org.testng.Assert.assertEquals;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
@Test(groups = "unit")
|
||||
public class Strings2Test {
|
||||
|
||||
public void testReplaceTokens() {
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user