Fix FixInvalidItalicTags eating a character before a dangling begin tag#12589
Merged
Conversation
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>
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.
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) + endTagcut the character before the dangling begin tag and appended an unbalanced end tag:<i>a</i><i><i>a</i</i>(corrupted tag)<i>a</i><i>ab</i>c<i><i>ab</i></i>(cdeleted)<i>ab</i>c<i>Hello</i> d<i><i>Hello</i> </i>(ddeleted)<i>Hello</i> dThis 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 singletext.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