Add the possibility to escape double brackets in replacements. Fix #187

This commit is contained in:
Federico Terzi 2020-02-26 21:03:52 +01:00
parent f429f58027
commit ec68fd767a

View File

@ -147,6 +147,11 @@ impl super::Renderer for DefaultRenderer {
content.replace.clone()
};
// Unescape any brackets (needed to be able to insert double brackets in replacement
// text, without triggering the variable system). See issue #187
let target_string = target_string.replace("\\{", "{")
.replace("\\}", "}");
// Render any argument that may be present
let target_string = utils::render_args(&target_string, &args);
@ -499,4 +504,21 @@ mod tests {
verify_render(rendered, "this is my ");
}
#[test]
fn test_render_escaped_double_brackets_should_not_consider_them_variable() {
let text = "this is :test";
let config = get_config_for(r###"
matches:
- trigger: ':test'
replace: "my \\{\\{unknown\\}\\}"
"###);
let renderer = get_renderer(config.clone());
let rendered = renderer.render_passive(text, &config);
verify_render(rendered, "this is my {{unknown}}");
}
}