Skip to content

Commit c13e1dc

Browse files
authored
Don't symlink the escaper module (#355)
The symlink doesn't work on Windows, and breaks NixOS builds. Closes #343
1 parent 40dffec commit c13e1dc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

maud/src/escape.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2+
// !!!!! PLEASE KEEP THIS IN SYNC WITH `maud_macros/src/escape.rs` !!!!!
3+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4+
15
extern crate alloc;
26

37
use alloc::string::String;

maud_macros/src/escape.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

maud_macros/src/escape.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2+
// !!!!!!!! PLEASE KEEP THIS IN SYNC WITH `maud/src/escape.rs` !!!!!!!!!
3+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4+
5+
extern crate alloc;
6+
7+
use alloc::string::String;
8+
9+
pub fn escape_to_string(input: &str, output: &mut String) {
10+
for b in input.bytes() {
11+
match b {
12+
b'&' => output.push_str("&"),
13+
b'<' => output.push_str("&lt;"),
14+
b'>' => output.push_str("&gt;"),
15+
b'"' => output.push_str("&quot;"),
16+
_ => unsafe { output.as_mut_vec().push(b) },
17+
}
18+
}
19+
}
20+
21+
#[cfg(test)]
22+
mod test {
23+
extern crate alloc;
24+
25+
use super::escape_to_string;
26+
use alloc::string::String;
27+
28+
#[test]
29+
fn it_works() {
30+
let mut s = String::new();
31+
escape_to_string("<script>launchMissiles()</script>", &mut s);
32+
assert_eq!(s, "&lt;script&gt;launchMissiles()&lt;/script&gt;");
33+
}
34+
}

0 commit comments

Comments
 (0)