Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
#[cfg(test)] |
| 2 |
use alloc::string::String; |
| 3 |
|
| 4 |
use markup::Render; |
| 5 |
|
| 6 |
use crate::CompactString; |
| 7 |
|
| 8 |
#[cfg_attr(docsrs, doc(cfg(feature = "markup")))] |
| 9 |
impl Render for CompactString { |
| 10 |
#[inline] |
| 11 |
fn render(&self, writer: &mut impl core::fmt::Write) -> core::fmt::Result { |
| 12 |
self.as_str().render(writer) |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
#[cfg(test)] |
| 17 |
#[test] |
| 18 |
fn test_markup() { |
| 19 |
const TEXT: &str = "<script>alert('Hello, world!')</script>"; |
| 20 |
|
| 21 |
markup::define!(Template<M: Render>(msg: M) { |
| 22 |
textarea { @msg } |
| 23 |
}); |
| 24 |
|
| 25 |
let compact = Template { |
| 26 |
msg: CompactString::from(TEXT), |
| 27 |
}; |
| 28 |
let control = Template { |
| 29 |
msg: String::from(TEXT), |
| 30 |
}; |
| 31 |
assert_eq!( |
| 32 |
compact.to_string(), |
| 33 |
"<textarea><script>alert('Hello, world!')</script></textarea>", |
| 34 |
); |
| 35 |
assert_eq!( |
| 36 |
control.to_string(), |
| 37 |
"<textarea><script>alert('Hello, world!')</script></textarea>", |
| 38 |
); |
| 39 |
} |