bugfix slash in backslash templating?

This commit is contained in:
Andrey 2024-10-07 01:15:12 -04:00
parent 25e796c9ed
commit 9909563c63
2 changed files with 6 additions and 4 deletions

View File

@ -19,9 +19,9 @@ public class VariableRegistryTest {
public void testBackSlash() {
VariableRegistry registry = new VariableRegistry();
registry.register("var1", "a\\b");
assertEquals("ab", registry.applyVariables("@@var1@@"));
assertEquals("a\\b", registry.applyVariables("@@var1@@"));
registry.register("var2", "a\\\\b");
assertEquals("a\\b", registry.applyVariables("@@var2@@"));
assertEquals("a\\\\b", registry.applyVariables("@@var2@@"));
}
@Test

View File

@ -207,7 +207,9 @@ public class VariableRegistry {
if (m.groupCount() < 2)
throw new IllegalStateException("Something broken in: [" + line + "]");
String key = m.group(2);
line = m.replaceFirst(function.apply(key));
String newValue = function.apply(key);
newValue = newValue.replace("\\", "\\\\"); // hack out symbol escaping
line = m.replaceFirst(newValue);
}
return line;
}
@ -322,7 +324,7 @@ public class VariableRegistry {
public void registerHex(String name, int value) {
register(name + _HEX_SUFFIX, Integer.toString(value, 16));
String _16_hex = String.format("\\\\x%02x\\\\x%02x", (value >> 8) & 0xFF, value & 0xFF);
String _16_hex = String.format("\\x%02x\\x%02x", (value >> 8) & 0xFF, value & 0xFF);
register(name + _16_HEX_SUFFIX, _16_hex);
}