- Notifications
You must be signed in to change notification settings - Fork22
fix(fix-flaws): handle UTF-8 characters and HTML entities#395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
caugner wants to merge8 commits intomainChoose a base branch fromfix-flaws
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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
Fix critical bug where byte offsets and character positions were mixedthroughout the codebase, causing incorrect position reporting for contentwith multi-byte UTF-8 characters (emojis, accented characters, etc.).Changes:- Add position_utils module with byte ↔ character conversion functions- Fix render.rs bug mixing character count with byte offset in end_col- Convert Issue byte columns to DisplayIssue character columns for output- Update actual_offset to convert character positions back to bytes- Improve char boundary checking with proper warnings- Document all position fields as bytes (internal) or characters (display)- Verify Comrak uses byte-based sourcepos (1-based)- Add comprehensive UTF-8 tests with emojis and accented charactersAll 153 existing tests pass. The fix ensures correct position handlingthroughout: tree-sitter/Comrak (bytes) → Issue (bytes) → DisplayIssue(characters) → file operations (bytes).
Fixes panic when byte_offset is in the middle of multi-byte characters(e.g., inside é). Adjusts to nearest boundary before counting chars.Verified with French content. All tests pass.
Fixes panics when running `content fix-flaws` on content with multi-byteUTF-8 characters (e.g., French accented characters like é).The issue occurred when calculating byte offsets for link replacements:- `offset - href.len()` could land inside a multi-byte character- String slicing at invalid boundaries caused panicsChanges:- Add character boundary validation in `collect_suggestions()` to ensure href start offsets are on valid UTF-8 boundaries- Add defensive checks in `apply_suggestions()` for both start and end offsets, skipping suggestions with invalid boundaries instead of panicking- Add char boundary check in `calc_offset()` as additional safety net- Add comprehensive tests for multi-byte character handlingThis ensures robust handling of international characters throughout thefix-flaws pipeline (French, German, Japanese, emoji, etc.).
Remove the unnecessary +10 byte margin when calculating search_startposition, which could cause finding wrong instances of duplicate hrefs.The rfind() search is precise enough without the extra margin.Additionally, enhance the warning message when an href cannot be locatedby including the actual content region that was searched. This makesdebugging much easier by showing what text was examined rather than justan offset number.
The fix-flaws command was failing to locate and fix broken links whenhrefs contained HTML entities (' for ', < for <, etc.). Thisoccurred because:1. Issue hrefs come from HTML output with encoded entities2. Suggestion URLs from redirects also contain encoded entities3. Raw markdown files contain literal characters (', <, etc.)4. The search/replace logic couldn't match encoded strings against literalsThis commit fixes the issue by:- Adding html-escape dependency to rari-tools- Decoding both href and suggestion before searching raw markdown- Decoding href in actual_offset() when calculating positions- Adding tests for HTML entity handlingResult: fix-flaws now successfully updates 22 French docs that werepreviously failing with "Could not locate href" warnings. The fixespreserve literal characters in markdown (no entities added).Fixes issues with French SVG documentation and other files containingaccented characters in URLs.5df22b7 to08e7bc6CompareSign up for freeto 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.
Description
Fixes two issues with the
fix-flawscommand:Motivation
Avoids that it fails intranslated-content's autofix workflow.
Additional details
Related issues and pull requests
Fixes#394.