Fix default impl of Escape::escape_to_buf and add a simple test case for EscapeJsonString
This commit is contained in:
parent
96eaea8479
commit
56c6af90d6
4 changed files with 23 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "Dwayne \"The Rock\" Johnson"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "<%\json &self.name %>"
|
||||
}
|
||||
|
|
@ -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 = '🍣')]
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue