From a8392df6b8f1a421fcec2f2b215e7a2f3e3a9a2f Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Sun, 14 Mar 2021 14:25:13 +0800 Subject: [PATCH] (test) add test to reproduce #422 --- tests/escape.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/escape.rs b/tests/escape.rs index 360a74fc5..563ab76b9 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -3,7 +3,7 @@ extern crate handlebars; #[macro_use] extern crate serde_json; -use handlebars::Handlebars; +use handlebars::{handlebars_helper, Handlebars}; #[test] fn test_escape_216() { @@ -19,3 +19,25 @@ fn test_escape_216() { r"\\\\ foo bar foobar foo#bar foo//bar foo\foo foo\\\foo\\foo \\foo {{FOO}} {{FOO}}" ); } + +#[test] +fn test_string_no_escape_422() { + let mut hbs = Handlebars::new(); + + handlebars_helper!(replace: |input: str, from: str, to: str| { + input.replace(from, to) + }); + hbs.register_helper("replace", Box::new(replace)); + + assert_eq!( + r#"some\ path"#, + hbs.render_template(r#"{{replace "some/path" "/" "\\ " }}"#, &()) + .unwrap() + ); + + assert_eq!( + r#"some\path"#, + hbs.render_template(r#"{{replace "some/path" "/" "\\" }}"#, &()) + .unwrap() + ); +}