Fix issue #5542 Sorting by name #5550
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue: Issue #5542
Summary:
Replaces the
<=>
operator with PHP’s Collator class for locale-aware string comparisons inApp\Sorting\SortSetOperationComparisons
. Using<=>
withstrtolower()
mishandles accented characters (e.g., "é" sorts after "z"), which is unreliable for languages with diacritics. Collator ensures accurate sorting based on the user’s locale.Changes:
Added a new protected static method
getCollator()
:Inside class
App\Sorting\SortSetOperationComparisons
, I've added$locale
is fetched from the user’s settings viaBookStack\Translation\LocaleManager
.class_exists(\Collator::class)
checks for the intl extension, returningnull
if unavailable (graceful fallback).Collator
object (ornull
) is used in the class’s comparison functions to handle sorting.Impact:
TL;DR: Swaps <=> for Collator to fix accented character sorting, with a fallback for missing intl.