Clone in a terminal:
Commit 09d6d11
Johan Mattsson - 2026-03-09T19:48:51+00:00
09d6d1188654b34d80f945fdaa50b4182cf1a989johan.mattsson.m@gmail.com

Escape less

Changed files (5)

Diff

diff --git a/Cargo.lock b/Cargo.lockindex 6a23775..0a2c2dd 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4,7 +4,7 @@ version = 4  [[package]] name = "kaja-html-macro"-version = "1.0.1"+version = "1.0.2" dependencies = [  "proc-macro-error",  "proc-macro2",diff --git a/Cargo.toml b/Cargo.tomlindex f18b4da..83ab54c 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,6 +1,6 @@ [package] name = "kaja-html-macro"-version = "1.0.1"+version = "1.0.2" edition = "2024" description = "HTML macro" license = "MIT"diff --git a/src/htmlquotes.rs b/src/htmlquotes.rsindex 9c9d1eb..8e0c955 100644--- a/src/htmlquotes.rs+++ b/src/htmlquotes.rs@@ -228,18 +228,16 @@ impl<'a> HtmlQuotes<'a> {          result.push_str(             r#"-            if __html_variable.chars().any(|c| ['<', '>', '/', '&', '\'', '"', '\\', '='].contains(&c)) {+            if __html_variable.chars().any(|c| ['<', '>', '&', '\'', '"', '='].contains(&c)) {                 let mut __escaped = String::with_capacity(2 * __html_variable.len());                  for c in __html_variable.as_str().chars() {                     match c {                         '<' => __escaped.push_str("&lt;"),                         '>' => __escaped.push_str("&gt;"),-                        '/' => __escaped.push_str("&#x2f;"),                         '&' => __escaped.push_str("&amp;"),                         '\'' => __escaped.push_str("&apos;"),                         '"' => __escaped.push_str("&quot;"),-                        '\\' => __escaped.push_str("&#x5c;"),                         '=' => __escaped.push_str("&equals;"),                         _ => __escaped.push(c),                     }diff --git a/tests/injection.rs b/tests/injection.rsindex 6b78fb8..fd89416 100644--- a/tests/injection.rs+++ b/tests/injection.rs@@ -44,8 +44,8 @@ fn test_escape_tag() {     assert!(html.contains("</html>"));      assert!(!html.contains("<script>test</script>"));-    assert!(html.contains("&lt;script&gt;test&lt;&#x2f;script&gt;"));-    assert!(html.contains("&lt;script&gt;anothertest&lt;&#x2f;script&gt;"));+    assert!(html.contains("&lt;script&gt;test&lt;/script&gt;"));+    assert!(html.contains("&lt;script&gt;anothertest&lt;/script&gt;"));      assert!(html.contains("<includedtag>OK</includedtag>")); }diff --git a/tests/other.rs b/tests/other.rsindex 5c6e91d..7262b77 100644--- a/tests/other.rs+++ b/tests/other.rs@@ -197,3 +197,16 @@ fn test_expression() {     println!("Generated HTML: {:?}", html);     assert!(html.contains("<div arg=\"test\"></div>")); }++fn test_import() -> String {+    return String::from("TEST");+}++#[test]+fn test_include_fn() {+    let content = html! {{+        <include test_import() />+    }};++    assert!(content.contains("TEST"));+}

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112