mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
rollback escaping support in template, as it is global
This commit is contained in:
parent
6e027ed3b7
commit
0405eb74fb
@ -94,7 +94,7 @@ public class Template implements LongFunction<String> {
|
|||||||
pos = m.end();
|
pos = m.end();
|
||||||
}
|
}
|
||||||
String partial = template.substring(pos);
|
String partial = template.substring(pos);
|
||||||
partial = unescape(partial);
|
// partial = unescape(partial);
|
||||||
literals.add(partial);
|
literals.add(partial);
|
||||||
if (literals.size() != funcCount + 1) {
|
if (literals.size() != funcCount + 1) {
|
||||||
throw new RuntimeException("The number of {} place holders in '" + template + "' should equal the number of functions.");
|
throw new RuntimeException("The number of {} place holders in '" + template + "' should equal the number of functions.");
|
||||||
@ -105,28 +105,28 @@ public class Template implements LongFunction<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for testing
|
// // for testing
|
||||||
public String unescape(String partial) {
|
// public String unescape(String partial) {
|
||||||
StringBuilder unescaped = new StringBuilder();
|
// StringBuilder unescaped = new StringBuilder();
|
||||||
try {
|
// try {
|
||||||
Pattern escapes = Pattern.compile("\\\\.");
|
// Pattern escapes = Pattern.compile("\\\\.");
|
||||||
Matcher m = escapes.matcher(partial);
|
// Matcher m = escapes.matcher(partial);
|
||||||
int pos = 0;
|
// int pos = 0;
|
||||||
|
//
|
||||||
while (m.find()) {
|
// while (m.find()) {
|
||||||
String prefix = partial.substring(pos,m.start());
|
// String prefix = partial.substring(pos,m.start());
|
||||||
unescaped.append(prefix);
|
// unescaped.append(prefix);
|
||||||
String segment = partial.substring(m.start(),m.end());
|
// String segment = partial.substring(m.start(),m.end());
|
||||||
unescaped.append(segment.substring(1));
|
// unescaped.append(segment.substring(1));
|
||||||
pos = m.end();
|
// pos = m.end();
|
||||||
}
|
// }
|
||||||
unescaped.append(partial.substring(pos));
|
// unescaped.append(partial.substring(pos));
|
||||||
|
//
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
return unescaped.toString();
|
// return unescaped.toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apply(long value) {
|
public String apply(long value) {
|
||||||
|
@ -52,25 +52,25 @@ public class TemplateTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
public void testUnescaping() {
|
// public void testUnescaping() {
|
||||||
String escaped="front \\' back";
|
// String escaped="front \\' back";
|
||||||
LongFunction<String> func = String::valueOf;
|
// LongFunction<String> func = String::valueOf;
|
||||||
Template template = new Template("{} extra", func);
|
// Template template = new Template("{} extra", func);
|
||||||
String unescaped = template.unescape(escaped);
|
// String unescaped = template.unescape(escaped);
|
||||||
assertThat(unescaped).isEqualTo("front ' back");
|
// assertThat(unescaped).isEqualTo("front ' back");
|
||||||
|
//
|
||||||
String unescaped2= template.unescape("\\' one \\' two \\'");
|
// String unescaped2= template.unescape("\\' one \\' two \\'");
|
||||||
assertThat(unescaped2).isEqualTo("' one ' two '");
|
// assertThat(unescaped2).isEqualTo("' one ' two '");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testBackslashUnescaping() {
|
// public void testBackslashUnescaping() {
|
||||||
String escaped="front \\\\\" back";
|
// String escaped="front \\\\\" back";
|
||||||
LongFunction<String> func = String::valueOf;
|
// LongFunction<String> func = String::valueOf;
|
||||||
Template template = new Template("{} extra", func);
|
// Template template = new Template("{} extra", func);
|
||||||
String unescaped = template.unescape(escaped);
|
// String unescaped = template.unescape(escaped);
|
||||||
assertThat(unescaped).isEqualTo("front \\\" back");
|
// assertThat(unescaped).isEqualTo("front \\\" back");
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user