Repository navigation
fix: keep the text of a script or a style raw in Element::inner_html - #32
Open
metalwarrior665 wants to merge 5 commits into
Open
metalwarrior665 wants to merge 5 commits into
metalwarrior665 wants to merge 5 commits into
Conversation
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
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 `&` 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Element::inner_htmlcalls scraper'sinner_html, which escapes the text of raw-text elements. A script's JSON came back with&as&and<as<. 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
&in its query. The images, videos and reel audio then failed to download. instagram-rs now reads the script'stext(), so it does not wait for this PR.For
style,script,xmp,iframe,noembed,noframesandplaintext,inner_htmlnow returns the element's text. Other elements do not change.Decisions to check
noscriptis left out. dom-serializer writes its text raw too, but with scripting off, html5ever parses elements inside it.text()would drop them.masterinto it instead of force-pushing, so the diff againstmasteris only this change.Tests
inner_html_of_raw_text_elements_is_not_escapedfailed before the fix.cargo fmt --all --check,cargo clippy --workspace --all-targetsandcargo test --workspace(338 passed) all pass withRUSTFLAGS=-D warnings.Generated by Claude Code