From 80148aa75335563106abae8680197e4adf3eb2eb Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Sun, 12 Jan 2020 00:47:52 +0200 Subject: Support escaping in string literals Do not attempt to parse escape sequences thoroughly. Instead let the Rust compiler to check the string literals and provide nice error messages if necessary. --- testing/templates/literals-escape.html | 2 ++ testing/tests/simple.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 testing/templates/literals-escape.html (limited to 'testing') diff --git a/testing/templates/literals-escape.html b/testing/templates/literals-escape.html new file mode 100644 index 0000000..4886cfb --- /dev/null +++ b/testing/templates/literals-escape.html @@ -0,0 +1,2 @@ +{{ '\x41' }}{{ '\n' }}{{ '\r' }}{{ '\t' }}{{ '\\' }}{{ '\0' }}{{ '\u{2665}' }}{{ '\'' }}{{ '\"' }}{{ '"' }} +{{ "\x41\n\r\t\\\0\u{2665}\'\"'" }} diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index 53f1122..a075d26 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -122,6 +122,19 @@ fn test_literals() { assert_eq!(s.render().unwrap(), "a\na\ntrue\nfalse"); } +#[derive(Template)] +#[template(path = "literals-escape.html")] +struct LiteralsEscapeTemplate {} + +#[test] +fn test_literals_escape() { + let s = LiteralsEscapeTemplate {}; + assert_eq!( + s.render().unwrap(), + "A\n\r\t\\\0♥'""\nA\n\r\t\\\0♥'"'" + ); +} + struct Holder { a: usize, } -- cgit