fix(mastodon): replace hand-rolled HTML sanitizer (CRITICAL UTF-8 panic)#27
Open
mduongvandinh wants to merge 2 commits intoRightNow-AI:mainfrom
Open
fix(mastodon): replace hand-rolled HTML sanitizer (CRITICAL UTF-8 panic)#27mduongvandinh wants to merge 2 commits intoRightNow-AI:mainfrom
mduongvandinh wants to merge 2 commits intoRightNow-AI:mainfrom
Conversation
The previous strip_html_tags() used html[result.len()..] byte indexing on a char-iterated string, causing panics on multi-byte UTF-8 content (emoji, CJK). Replace with a safe char-based tag stripper and use html_escape::decode_html_entities for comprehensive entity decoding including numeric entities (’, ’).
Move html-escape from direct crate dependency to workspace-level declaration in root Cargo.toml, per CONTRIBUTING.md convention.
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.
Summary
strip_html_tags()panics on multi-byte UTF-8 content (emoji, CJK)html-escapecrate for comprehensive entity supportBug Detail
The old code used
html[result.len()..]byte indexing on a char-iterated string. Whenresultcontained multi-byte chars (e.g. emoji🦀= 4 bytes),result.len()returned a byte offset that didn't correspond to the current position inhtml, causing index-out-of-bounds panic.Changes
strip_html_tags()with safe char-based state machine (no source string back-indexing)html-escape = "0.2"dependency for proper entity decoding (named + numeric + hex)</div>and</li>(in addition to existing<br>,</p>)Test plan
cargo test -p openfang-channels)cargo clippy -p openfang-channels --all-targets -- -D warnings)Files changed
crates/openfang-channels/src/mastodon.rs(+54, -21)crates/openfang-channels/Cargo.toml(+1)