Skip to content

fix: keep the text of a script or a style raw in Element::inner_html - #32

Open
metalwarrior665 wants to merge 5 commits into
masterfrom
claude/peaceful-ride-pbk3vs
Open

metalwarrior665 wants to merge 5 commits into
masterfrom
claude/peaceful-ride-pbk3vs

Conversation

@metalwarrior665

Copy link
Copy Markdown
Member

Element::inner_html calls scraper's inner_html, which escapes the text of raw-text elements. A script's JSON came back with & as &amp; and < as &lt;. cheerio's .html() keeps that text raw, so JS code that reads inline JSON with $(script).html() breaks when it is ported to Rust.

It broke instagram-rs: every signed CDN URL in a post page's inline JSON got &amp; in its query. The images, videos and reel audio then failed to download. instagram-rs now reads the script's text(), so it does not wait for this PR.

For style, script, xmp, iframe, noembed, noframes and plaintext, inner_html now returns the element's text. Other elements do not change.

Decisions to check

  • noscript is left out. dom-serializer writes its text raw too, but with scripting off, html5ever parses elements inside it. text() would drop them.
  • Merge commit. The branch is the one from fix: port the JS redirect and sitemap fixes of 16 to 23 November 2026 #31, which was squash-merged. I merged master into it instead of force-pushing, so the diff against master is only this change.

Tests

  • The new test inner_html_of_raw_text_elements_is_not_escaped failed before the fix.
  • cargo fmt --all --check, cargo clippy --workspace --all-targets and cargo test --workspace (338 passed) all pass with RUSTFLAGS=-D warnings.

Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XtpQtWeEaZRLDjwQCtwyk
…rawlee #4412)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XtpQtWeEaZRLDjwQCtwyk
scraper's inner_html escapes the text of raw-text elements, so `&` in a
script's JSON came back as `&amp;` and broke the URLs in it. cheerio's
.html() keeps that text raw, and Element::inner_html now does the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016XtpQtWeEaZRLDjwQCtwyk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants