Skip to content

Fix FixInvalidItalicTags leaving some two-line stray-tag shapes unrepaired#12593

Merged
niksedk merged 1 commit into
mainfrom
fix/italic-tags-two-line-stray-tags
Jul 18, 2026
Merged

Fix FixInvalidItalicTags leaving some two-line stray-tag shapes unrepaired#12593
niksedk merged 1 commit into
mainfrom
fix/italic-tags-two-line-stray-tags

Conversation

@niksedk

@niksedk niksedk commented Jul 18, 2026

Copy link
Copy Markdown
Member

Follow-up to the #12579 review, which showed that tightening the "duplicated" condition in the two-line stray-italic-tag branches was a regression. This PR fixes the underlying issue correctly.

The problem: the two-line branches for only four </i> tags / only four <i> tags use an asymmetric condition (lines[1].EndsWith checked twice, lines[0]'s end never checked — identical in SE 4). Shapes matching the loose condition are repaired to whole-line italics, but near-miss shapes fall through and FixInvalidItalicTags returns the invalid tags unchanged:

Input Before After
</i>Hello</i>a</i> + World</i> unchanged (invalid) <i>Helloa</i> + <i>World</i>
a</i>b</i> + c</i>d</i> unchanged (invalid) <i>ab</i> + <i>cd</i>
</i>Hello</i>b</i>c</i> + plain unchanged (invalid) <i>Hellobc</i> + plain
(mirrors with <i>) unchanged (invalid) repaired

The fix: under these count guards (exactly four copies of a single tag, two lines) the stray tags carry no pairing information — so drop the positional condition entirely and repair per line: strip the stray tags from each line containing one and wrap that line in proper <i>...</i>; lines without a tag are kept as-is (so a plain second line does not become italic). This matches the method's established heuristic for the single-stray-end-tag case (Foo.</i><i>Foo.</i>).

Compatibility: output is byte-identical for every shape the old condition matched (verified against current main on all six such shapes) — this only turns previously-unfixed invalid output into valid italics.

Tests: 12 new theory cases pin both the long-standing shapes and the newly repaired ones. All 520 libse, 237 seconv, and 14 libuilogic tests pass.

🤖 Generated with Claude Code

…aired

The two-line branches for "only four </i> tags" / "only four <i> tags"
had an asymmetric condition (lines[1].EndsWith checked twice, lines[0]'s
end never) - identical in SE 4, and load-bearing: shapes it matched were
repaired to whole-line italics, but near-miss shapes (e.g. second line
not starting with the tag, or all four tags on the first line) fell
through and the function returned the invalid tags unchanged.

Rather than tightening the condition (which would repair fewer shapes -
see PR #12579 review), generalize it: under the count guard the stray
tags carry no pairing information, so strip them from each line that
contains one and wrap that line in proper <i>...</i>; tag-less lines are
kept as-is. Output is byte-identical for every previously matched shape,
and the fall-through shapes now come out as valid italics.

Tests pin both the long-standing shapes and the newly repaired ones.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@niksedk
niksedk merged commit 48542e8 into main Jul 18, 2026
1 of 3 checks passed
@niksedk
niksedk deleted the fix/italic-tags-two-line-stray-tags branch July 18, 2026 09:08
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