Skip to content

Fix line break enumerator infinite loop - #21808

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
irihitech:fix/line-break-enumerator-infinite-loop
Jul 21, 2026
Merged

Fix line break enumerator infinite loop#21808
MrJul merged 2 commits into
AvaloniaUI:mainfrom
irihitech:fix/line-break-enumerator-infinite-loop

Conversation

@rabbitism

Copy link
Copy Markdown
Contributor

What does the pull request do?

LineBreakEnumerator now goes to infinite loop when breaking an empty string. This PR resolves this issue.

What is the current behavior?

Infinite loop

What is the updated/expected behavior with this PR?

Immediately returns false when moving next.

How was the solution implemented (if it's not obvious)?

Obvious

Checklist

Breaking changes

No, I don't think anyone is utilizing this feature or bug.

Obsoletions / Deprecations

Fixed issues

Empty text has no content and should not produce any line break
opportunities. Short-circuit in MoveNext before entering the
read/rule loop, while keeping the PeekAt EndOfText fix as a
defensive safeguard.
@Gillibald

Copy link
Copy Markdown
Contributor

Isn't the issue that PeekAt does not yield a state that indicates the end of text for empty text? https://github.com/irihitech/Avalonia/blob/703085f4378ae8a1fea8fc58dee5c0825ede4161/src/Avalonia.Base/Media/TextFormatting/Unicode/LineBreakEnumerator.cs#L1639

@rabbitism

rabbitism commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Isn't the issue that PeekAt does not yield a state that indicates the end of text for empty text? https://github.com/irihitech/Avalonia/blob/703085f4378ae8a1fea8fc58dee5c0825ede4161/src/Avalonia.Base/Media/TextFormatting/Unicode/LineBreakEnumerator.cs#L1639

I tried that approach, but the empty string returns true first and then false, which means empty string will generate a line break, I think that's not expected.

If that is expected, then I can just mark EndOfText = true, let me know your opinion.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0067547-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug area-textprocessing backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 20, 2026
@MrJul
MrJul requested a review from Gillibald July 21, 2026 07:50

@Gillibald Gillibald left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This is the simplest solution that fixes the issue

@MrJul
MrJul added this pull request to the merge queue Jul 21, 2026
Merged via the queue into AvaloniaUI:main with commit 14118ef Jul 21, 2026
10 checks passed
MrJul pushed a commit that referenced this pull request Jul 29, 2026
* Add failing test: LineBreakEnumerator infinite loop on empty string

* Return false immediately for empty string in LineBreakEnumerator

Empty text has no content and should not produce any line break
opportunities. Short-circuit in MoveNext before entering the
read/rule loop, while keeping the PeekAt EndOfText fix as a
defensive safeguard.
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants