From c13e1dcc489d1132e56c7284af49c620f7345b91 Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Sun, 18 Sep 2022 22:47:39 +1000 Subject: [PATCH] Don't symlink the escaper module (#355) The symlink doesn't work on Windows, and breaks NixOS builds. Closes #343 --- maud/src/escape.rs | 4 ++++ maud_macros/src/escape.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) mode change 120000 => 100644 maud_macros/src/escape.rs diff --git a/maud/src/escape.rs b/maud/src/escape.rs index f5c24d2e..94cdeec1 100644 --- a/maud/src/escape.rs +++ b/maud/src/escape.rs @@ -1,3 +1,7 @@ +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!!!! PLEASE KEEP THIS IN SYNC WITH `maud_macros/src/escape.rs` !!!!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + extern crate alloc; use alloc::string::String; diff --git a/maud_macros/src/escape.rs b/maud_macros/src/escape.rs deleted file mode 120000 index fc68eadb..00000000 --- a/maud_macros/src/escape.rs +++ /dev/null @@ -1 +0,0 @@ -../../maud/src/escape.rs \ No newline at end of file diff --git a/maud_macros/src/escape.rs b/maud_macros/src/escape.rs new file mode 100644 index 00000000..49ece776 --- /dev/null +++ b/maud_macros/src/escape.rs @@ -0,0 +1,34 @@ +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// !!!!!!!! PLEASE KEEP THIS IN SYNC WITH `maud/src/escape.rs` !!!!!!!!! +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +extern crate alloc; + +use alloc::string::String; + +pub fn escape_to_string(input: &str, output: &mut String) { + for b in input.bytes() { + match b { + b'&' => output.push_str("&"), + b'<' => output.push_str("<"), + b'>' => output.push_str(">"), + b'"' => output.push_str("""), + _ => unsafe { output.as_mut_vec().push(b) }, + } + } +} + +#[cfg(test)] +mod test { + extern crate alloc; + + use super::escape_to_string; + use alloc::string::String; + + #[test] + fn it_works() { + let mut s = String::new(); + escape_to_string("", &mut s); + assert_eq!(s, "<script>launchMissiles()</script>"); + } +}