Skip to content

Fix FixInvalidItalicTags eating a character before a dangling begin tag#12589

Merged
niksedk merged 1 commit into
mainfrom
fix/fix-invalid-italic-tags-dangling-tag
Jul 18, 2026
Merged

Fix FixInvalidItalicTags eating a character before a dangling begin tag#12589
niksedk merged 1 commit into
mainfrom
fix/fix-invalid-italic-tags-dangling-tag

Conversation

@niksedk

@niksedk niksedk commented Jul 18, 2026

Copy link
Copy Markdown
Member

Found in a bug hunt and verified against the real library. In HtmlUtil.FixInvalidItalicTags, the "two <i>, one </i>" repair path had an off-by-one in its near-end branch — Substring(0, lastIndex - 1) + endTag cut the character before the dangling begin tag and appended an unbalanced end tag:

Input Old output New output
<i>a</i><i> <i>a</i</i> (corrupted tag) <i>a</i>
<i>ab</i>c<i> <i>ab</i></i> (c deleted) <i>ab</i>c
<i>Hello</i> d<i> <i>Hello</i> </i> (d deleted) <i>Hello</i> d

This runs inside "Fix common errors" → fix invalid italic tags, so the old behavior silently destroyed subtitle text. The bug has been there since 2021 and is also present in SE4.

The fix: the sibling branch was already removing exactly the spurious begin tag in a roundabout way (lastIndex - 1 + endTag.Length == lastIndex + beginTag.Length), so both branches collapse into a single text.Remove(lastIndex, beginTag.Length) that keeps all surrounding text.

Unit tests added for the three corruption cases; the full LibSETests suite passes (502/502).

🤖 Generated with Claude Code

In the "two begin tags, one end tag" repair path, the near-end branch
did Substring(0, lastIndex - 1) + endTag: it cut the character before
the dangling begin tag and appended an unbalanced end tag, so
"<i>ab</i>c<i>" became "<i>ab</i></i>" (the "c" was silently lost) and
"<i>a</i><i>" became "<i>a</i</i>" (a corrupted tag). The other branch
was already just removing the spurious begin tag in a roundabout way
(lastIndex - 1 + endTag.Length == lastIndex + beginTag.Length), so both
collapse into a single Remove that keeps all surrounding text.

Runs as part of "Fix common errors" (fix invalid italic tags), so the
old behavior destroyed subtitle text. Present since 2021, also in SE4.
Unit tests added for the three corruption cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@niksedk
niksedk merged commit b38b5b0 into main Jul 18, 2026
1 of 3 checks passed
@niksedk
niksedk deleted the fix/fix-invalid-italic-tags-dangling-tag branch July 18, 2026 08:16
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