Repository navigation
fix: preserve stylesheet text when rewriting encodings - #520
Open
maximilliangrand wants to merge 2 commits into
Open
maximilliangrand wants to merge 2 commits into
maximilliangrand wants to merge 2 commits into
Conversation
This was referenced Oct 7, 2026
Member
|
Thank you for the PR. Now, this is a pretty big problem I've been seeing when it comes to both stylesheets and HTML. I believe this commit improves a lot of things, I need to review and test it more, will report here briefly. |
There was a problem hiding this comment.
🟢 Approval recommended
The decoding paths and output metadata are consistent, with focused regression coverage for the affected cases.
0 open findings
What changed in this PR
Preserves stylesheet text by decoding source bytes correctly and marking rewritten CSS data URLs as UTF-8.
Changes:
- Centralizes stylesheet decoding for linked and imported CSS.
- Emits rewritten stylesheet data URLs with UTF-8 metadata.
- Adds regression coverage for multiple encodings and import syntaxes.
| File | Description |
|---|---|
src/css.rs |
Adds shared decoding and UTF-8 rewriting. |
src/html.rs |
Uses shared decoding for linked stylesheets. |
tests/css/embed_css.rs |
Tests encoded CSS imports. |
tests/html/walk.rs |
Tests encoded linked stylesheets. |
tests/cli/basic.rs |
Updates UTF-8 data URL expectations. |
tests/cli/local_files.rs |
Updates local stylesheet expectations. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
@maximilliangrand could you please rebase it when you get a minute? |
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.
Related to #351.
A linked stylesheet served as Windows-1252 is decoded before rewriting, but its UTF-8 output is embedded with the original Windows-1252 charset. For example,
content: 'café'becomes mojibake when the saved page is opened. CSS@importhas the complementary problem: its bytes are decoded as UTF-8 even when another charset is declared.Reuse the linked-stylesheet decoding path for imports, then label all rewritten stylesheet data URLs as UTF-8. Keep the UTF-8 fallback when charset metadata is absent. No new dependency or public API is needed.
Regression coverage exercises linked stylesheets and all three import forms (quoted string, quoted URL, unquoted URL), using Windows-1252, explicit UTF-8, and no charset. Existing CLI expectations only gain the UTF-8 charset parameter; their stylesheet payloads are unchanged.
Validation:
cargo test --all --locked: 300 passed.cargo fmt --all -- --checkandgit diff --check: pass.::beforecontent is"café".This handles charset metadata already returned by asset retrieval; it does not add CSS
@charsetsniffing or change document/frame encoding.AI assistance: implemented and validated with OpenAI Codex.