Add the possibility to escape double brackets in replacements. Fix #187
This commit is contained in:
parent
f429f58027
commit
ec68fd767a
|
@ -147,6 +147,11 @@ impl super::Renderer for DefaultRenderer {
|
||||||
content.replace.clone()
|
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
|
// Render any argument that may be present
|
||||||
let target_string = utils::render_args(&target_string, &args);
|
let target_string = utils::render_args(&target_string, &args);
|
||||||
|
|
||||||
|
@ -499,4 +504,21 @@ mod tests {
|
||||||
|
|
||||||
verify_render(rendered, "this is my ");
|
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}}");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user