cloudflare / cloudflare/lol-html

HTML Entities are not Decoded in Attributes.

Open
#131 0 comments 5 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
2.1k
Forks
111
PR merge metrics
No merged PRs in 30d

Description

```rust
#[test]
fn test() {
lol_html::rewrite_str(
r#"
Foo & Bar
"#,
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();
}
```

```rust
thread 'test' panicked at 'assertion failed: `(left == right)`
left: `Some("Foo & 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`.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failing Rust test in the issue and trace the get_attribute path used by the img element handler. Done means the handler receives "Foo & Bar" instead of the source text "Foo & Bar", while the existing rewrite operation still succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.