lol-html icon indicating copy to clipboard operation
lol-html copied to clipboard

HTML Entities are not Decoded in Attributes.

Open kevincox opened this issue 3 years ago • 0 comments
trafficstars

#[test]
fn test() {
	lol_html::rewrite_str(
		r#"
		<img alt="Foo &amp; Bar" src=example.png>
		"#,
		lol_html::RewriteStrSettings {
			element_content_handlers: vec![
				lol_html::element!("img", |e| {
					assert_eq!(e.get_attribute("alt").as_deref(), Some("Foo & Bar"));
					Ok(())
				}),
			],
			..Default::default()
		}).unwrap();
}
thread 'test' panicked at 'assertion failed: `(left == right)`
  left: `Some("Foo &amp; Bar")`,
 right: `Some("Foo & Bar")`', src/main.rs:10:21

Expected behaviour: The entities are decoded. Actual behaviour: The source representation of the attribute contents are returned.

Workaround: Manually decode the string returned from get_attribute.

kevincox avatar May 23 '22 17:05 kevincox