From c4409241b68f5a1780daa78ae912389f63064f91 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 14 Nov 2020 21:19:59 +0100 Subject: [PATCH] Disable argument rendering for matches unless args are present. Fix #465 --- src/render/default.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/render/default.rs b/src/render/default.rs index 40d1857..3415f0d 100644 --- a/src/render/default.rs +++ b/src/render/default.rs @@ -238,13 +238,15 @@ impl super::Renderer for DefaultRenderer { // 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("\\}", "}"); + let mut target_string = target_string.replace("\\{", "{").replace("\\}", "}"); // Render any argument that may be present - let target_string = utils::render_args(&target_string, &args); + if !args.is_empty() { + target_string = utils::render_args(&target_string, &args); + } // Handle case propagation - let target_string = if m.propagate_case { + target_string = if m.propagate_case { let trigger = &m.triggers[trigger_offset]; // The check should be carried out from the position of the first @@ -518,6 +520,25 @@ mod tests { verify_render(rendered, "Hi Jon"); } + #[test] + fn test_render_passive_simple_match_no_args_should_not_replace_args_syntax() { + let text = ":greet"; + + let config = get_config_for( + r###" + matches: + - trigger: ':greet' + replace: "Hi $0$" + "###, + ); + + let renderer = get_renderer(config.clone()); + + let rendered = renderer.render_passive(text, &config); + + verify_render(rendered, "Hi $0$"); + } + #[test] fn test_render_passive_simple_match_with_multiple_args() { let text = ":greet/Jon/Snow/";