Fix encryption of string containing curly braces (#774)
* Add test to reproduce curly brace problem * Fix stripping prefix if string contains curly brace
This commit is contained in:
committed by
Spencer Gibb
parent
a7bd68cf93
commit
ac76f6e970
@@ -117,7 +117,7 @@ class EnvironmentPrefixHelper {
|
||||
if (value.contains(ESCAPE)) {
|
||||
return value.substring(value.indexOf(ESCAPE) + ESCAPE.length());
|
||||
}
|
||||
return value.substring(value.lastIndexOf("}") + 1);
|
||||
return value.replaceFirst("^(\\{.*?:.*?\\})+", "");
|
||||
}
|
||||
|
||||
private String removeEnvironmentPrefix(String input) {
|
||||
|
||||
@@ -135,6 +135,20 @@ public class EncryptionControllerTests {
|
||||
assertThat("Prefix must be stripped prior to encrypt", captor.getValue(), not(containsString("{key:test}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encryptDecyptTextWithCurlyBrace() {
|
||||
this.controller = new EncryptionController(
|
||||
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
|
||||
|
||||
String plain = "textwith}brace";
|
||||
|
||||
String cipher = this.controller.encrypt(plain,
|
||||
MediaType.APPLICATION_FORM_URLENCODED);
|
||||
String decrypt = this.controller.decrypt(cipher,
|
||||
MediaType.APPLICATION_FORM_URLENCODED);
|
||||
assertEquals(plain, decrypt);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addEnvironment() {
|
||||
TextEncryptorLocator locator = new TextEncryptorLocator() {
|
||||
|
||||
@@ -81,4 +81,14 @@ public class EnvironmentPrefixHelperTests {
|
||||
assertEquals("mykey", keys.get("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextWithCurlyBracesNoPrefix() {
|
||||
assertEquals("textwith}brac{es", this.helper.stripPrefix("textwith}brac{es"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextWithCurlyBracesPrefix() {
|
||||
assertEquals("textwith}brac{es{and}prefix", this.helper
|
||||
.stripPrefix("{key:foo}{name:bar}textwith}brac{es{and}prefix"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user