Fix default impl of Escape::escape_to_buf and add a simple test case for EscapeJsonString

This commit is contained in:
Michael Pfaff 2025-03-13 19:01:45 -04:00
commit 56c6af90d6
4 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,3 @@
{
"name": "Dwayne \"The Rock\" Johnson"
}

View file

@ -0,0 +1,3 @@
{
"name": "<%\json &self.name %>"
}

View file

@ -85,6 +85,22 @@ fn json() {
);
}
#[derive(Render)]
#[template(path = "json_escape.stpl")]
struct JsonEscape {
name: String,
}
#[test]
fn json_escape() {
assert_render(
"json_escape",
JsonEscape {
name: String::from(r#"Dwayne "The Rock" Johnson"#),
},
);
}
#[derive(Render)]
#[template(path = "custom_delimiter.stpl")]
#[template(delimiter = '🍣')]

View file

@ -89,6 +89,7 @@ pub trait Escape: const EscapeMeta {
i = j + c.len_utf8();
}
}
buffer.push_str(&string[i..]);
}
/// Writes the `string` to the `buffer`, applying any necessary escaping.