Skip to content

Fix mojibake for non-ASCII text on lines with wiki markup - #20

Merged
rethab merged 1 commit into
mainfrom
fix/issue-1003
Jul 12, 2026
Merged

Fix mojibake for non-ASCII text on lines with wiki markup#20
rethab merged 1 commit into
mainfrom
fix/issue-1003

Conversation

@rethab

@rethab rethab commented Jul 12, 2026

Copy link
Copy Markdown
Owner

The Jira wiki-to-markdown parser corrupted non-ASCII characters (Greek, Cyrillic, CJK, accented Latin, emoji, etc.) whenever they appeared on a line that also contained wiki markup such as bold, a heading, or a list marker.

In secondPass's tokenized-line loop, the fallback branch for bytes that don't start a recognized token wrote out.WriteRune(rune(line[beg])) while advancing one byte at a time. This treats every raw UTF-8 byte as its own Unicode code point and re-encodes it, mangling any multibyte sequence. Lines without any markup skip this loop entirely (they're written verbatim), which is why the bug only showed up on lines mixing wiki syntax with non-ASCII text.

The fix decodes a full rune at the current byte offset with utf8.DecodeRuneInString and advances by its actual byte width instead of a fixed one byte, so multibyte characters pass through intact regardless of what markup surrounds them on the line.

Added a test case mixing bold markup with Greek, Cyrillic, and Japanese text to lock in the fix.

Addresses ankitpokhrel#1003.

secondPass's tokenized-line loop wrote unmatched bytes with
out.WriteRune(rune(line[beg])), treating each raw UTF-8 byte as its
own code point and advancing beg by one byte at a time. Any
multibyte character (Greek, Cyrillic, CJK, accented Latin, emoji)
on a line containing wiki markup like *bold* or a heading got
corrupted into mojibake, since only lines with at least one token
go through this byte-wise fallback.

Decode a full rune at the current byte offset with
utf8.DecodeRuneInString and advance by its byte width instead.
@rethab
rethab merged commit 88346cf into main Jul 12, 2026
1 check passed
@rethab
rethab deleted the fix/issue-1003 branch July 12, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant