- // Primary collision
- // Keep whichever one sorts first in the main collator
- if ( $this->mainCollator->compare( $letter, $letterMap[$key] ) < 0 ) {
+ // Primary collision (two characters with the same sort position).
+ // Keep whichever one sorts first in the main collator.
+ $comp = $this->mainCollator->compare( $letter, $letterMap[$key] );
+ wfDebug( "Primary collision '$letter' '{$letterMap[$key]}' (comparison: $comp)\n" );
+ // If that also has a collision, use codepoint as a tiebreaker.
+ if ( $comp === 0 ) {
+ $comp = UtfNormal\Utils::utf8ToCodepoint( $letter ) <=>
+ UtfNormal\Utils::utf8ToCodepoint( $letterMap[$key] );
+ }
+ if ( $comp < 0 ) {