From ec68fd767ab01c9534afafbb3953a7692c8404ba Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 26 Feb 2020 21:03:52 +0100 Subject: [PATCH] Add the possibility to escape double brackets in replacements. Fix #187 --- src/render/default.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/render/default.rs b/src/render/default.rs index 804bb4e..55fa5cc 100644 --- a/src/render/default.rs +++ b/src/render/default.rs @@ -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}}"); + } } \ No newline at end of file