fixed tests and double escaping of escape symbols

This commit is contained in:
Jonathan Shook 2020-04-13 16:29:16 -05:00
parent 580eac4b09
commit 1cce7d8a61
3 changed files with 12 additions and 2 deletions

View File

@ -31,7 +31,8 @@ public class BindingEscapingTest {
@Test
public void testEscapedBindings() {
DataMapper<String> mapper = VirtData.getMapper("Template('\"-{}-\"Func(234)\\\"\\)',NumberNameToString());'",String.class);
DataMapper<String> mapper = VirtData.getMapper("Template('\"-{}-\"Func(234)\\\\\"\\\\)',NumberNameToString())" +
";'",String.class);
String s = mapper.get(234);
assertThat(s).isEqualTo("\"-two hundred and thirty four-\"Func(234)\\\"\\)");
}

View File

@ -109,7 +109,7 @@ public class Template implements LongFunction<String> {
public String unescape(String partial) {
StringBuilder unescaped = new StringBuilder();
try {
Pattern escapes = Pattern.compile("\\\\[^\\\\]");
Pattern escapes = Pattern.compile("\\\\.");
Matcher m = escapes.matcher(partial);
int pos = 0;

View File

@ -64,4 +64,13 @@ public class TemplateTest {
assertThat(unescaped2).isEqualTo("' one ' two '");
}
@Test
public void testBackslashUnescaping() {
String escaped="front \\\\\" back";
LongFunction<String> func = String::valueOf;
Template template = new Template("{} extra", func);
String unescaped = template.unescape(escaped);
assertThat(unescaped).isEqualTo("front \\\" back");
}
}