Skip to content

Use ordinal comparisons for pseudoclass checks and IterationCount.Parse - #22604

Merged
MrJul merged 4 commits into
AvaloniaUI:mainfrom
hazeliscoding:fix/ordinal-pseudoclass-checks
Oct 27, 2026
Merged

MrJul merged 4 commits into
AvaloniaUI:mainfrom
hazeliscoding:fix/ordinal-pseudoclass-checks

Conversation

@hazeliscoding

Copy link
Copy Markdown
Contributor

What does the pull request do?

Classes, TypeNameAndClassSelector and IterationCount.Parse checked for :, - and INFINITE with culture-sensitive StartsWith/EndsWith. These are syntax checks, so they're now ordinal. Under a non-English culture, these calls open an ICU collator on the UI thread at startup, as #22582 describes.

What is the current behavior?

Culture-sensitive comparisons ignore characters such as the soft hyphen (U+00AD). With a soft hyphen before the colon, Classes.Add rejects a class as a pseudoclass, Clear() and Replace() keep it, and the selector string leaves out its .. IterationCount.Parse also accepts Infinite followed by a soft hyphen.

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

Besides the two methods named in the issue, I changed the other StartsWith(":") checks in Classes.Clear, Classes.Replace and TypeNameAndClassSelector, so a class that Add accepts isn't treated as a pseudoclass elsewhere.

The tests use the soft hyphen to catch a culture-sensitive comparison. They're in the first commit and fail without the second. StartsWith('-') in IterationCount.Parse has no test: the only visible difference is which exception is thrown when a soft hyphen comes before the minus sign.

Fixed issues

Fixes #22582

…t checks

Culture-sensitive comparisons ignore a soft hyphen (U+00AD), so a class
that starts with one followed by ':' is treated as a pseudoclass, and
"Infinite" followed by one still parses as Infinite.
…t.Parse

These checks test syntax, so a culture-sensitive comparison gives wrong
answers for ignorable characters and opens an ICU collator on the UI
thread at startup.
maxkatz6
maxkatz6 previously approved these changes Oct 26, 2026
@maxkatz6 maxkatz6 added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch area-controls labels Oct 26, 2026
@maxkatz6

Copy link
Copy Markdown
Member

@cla-avalonia comment

@cla-avalonia

cla-avalonia commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@hazeliscoding

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

NuGet packages

The packages for this pull request have been published (workflow run):

The char overload was already ordinal, but no test covers this check,
so say so explicitly, as the EndsWith check above it does.
@MrJul
MrJul enabled auto-merge October 26, 2026 12:39
@MrJul
MrJul added this pull request to the merge queue Oct 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 27, 2026
@MrJul
MrJul added this pull request to the merge queue Oct 27, 2026
Merged via the queue into AvaloniaUI:main with commit c67550d Oct 27, 2026
10 checks passed
@hazeliscoding
hazeliscoding deleted the fix/ordinal-pseudoclass-checks branch October 27, 2026 14:26
MrJul pushed a commit that referenced this pull request Nov 2, 2026
…se (#22604)

* test: add failing tests for culture-sensitive class and IterationCount checks

Culture-sensitive comparisons ignore a soft hyphen (U+00AD), so a class
that starts with one followed by ':' is treated as a pseudoclass, and
"Infinite" followed by one still parses as Infinite.

* fix: use ordinal comparisons for pseudoclass checks and IterationCount.Parse

These checks test syntax, so a culture-sensitive comparison gives wrong
answers for ignorable characters and opens an ICU collator on the UI
thread at startup.

* refactor: spell out the ordinal comparison in IterationCount.Parse

The char overload was already ordinal, but no test covers this check,
so say so explicitly, as the EndsWith check above it does.
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Nov 2, 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.

Classes.ThrowIfPseudoclass and IterationCount.Parse compare culture-sensitively, opening an ICU collator on Android's UI thread at startup

5 participants