Skip to content

Break StandardOrder.Compare ties between case variants ordinally [patch] - #200

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/197-compare-total-order
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/197-compare-total-order

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

StandardOrder.Compare returned 0 for different strings that differ only in case ("Title"/"title", "MyKey"/"mykey"). Used as a sorted-collection comparer, it made SortedDictionary throw and SortedSet silently drop keys.

When the standard-order comparison ties on two different strings, Compare now falls back to string.CompareOrdinal, so it returns 0 only for the same string. Known keys keep their order relative to each other and to unknown keys. Compare isn't used inside the library, so CombineFrontmatter output is unchanged.

Tests (StandardOrderCompareTotalOrderTests): antisymmetry for the issue's case-variant pairs, the SortedDictionary and SortedSet repros keeping every key, and the order across positions staying the same. Without the fix, 5 of the 7 tests fail. With it, the full suite passes (304/304).

Fixes #197

🤖 Generated with Claude Code

https://claude.ai/code/session_019MupvoiQ9WM1vUJoCzYJ6W


Generated by Claude Code

Compare returned 0 for "Title"/"title" and "MyKey"/"mykey", so a
SortedDictionary built on it threw and a SortedSet dropped keys. When the
standard-order comparison ties on two different strings, fall back to an
ordinal comparison, so 0 means the same string.

Fixes #197

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MupvoiQ9WM1vUJoCzYJ6W
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ffb5838 into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/197-compare-total-order branch October 9, 2026 08:07
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.

StandardOrder.Compare returns 0 for case-variant keys ("Title"/"title"), so a SortedDictionary throws and a SortedSet silently drops keys

1 participant