Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rariPublic

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 intomain
base:main
Choose a base branch
Loading
fromfix-flaws

Conversation

@caugner
Copy link
Contributor

Description

Fixes two issues with thefix-flaws command:

  • Byte and character length were mixed.
  • HTML entity encoding caused mismatches.

Motivation

Avoids that it fails intranslated-content's autofix workflow.

Additional details

Related issues and pull requests

Fixes#394.

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 (&#x27; for ', &lt; 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.
@caugnercaugnerforce-pushed thefix-flaws branch 2 times, most recently from5df22b7 to08e7bc6CompareNovember 26, 2025 22:51
@caugnercaugner marked this pull request as ready for reviewNovember 28, 2025 10:56
@caugnercaugner requested review froma team andmdn-bot ascode ownersNovember 28, 2025 10:56
@caugnercaugner requested a review fromLeoMcANovember 28, 2025 10:56
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mdn-botmdn-botAwaiting requested review from mdn-botmdn-bot is a code owner

@LeoMcALeoMcAAwaiting requested review from LeoMcALeoMcA is a code owner automatically assigned from mdn/engineering

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fix-flaws duplicates content + fails to apply suggestions

1 participant

@caugner

[8]ページ先頭

©2009-2025 Movatter.jp