-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix issue #5542 Sorting by name #5550
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix issue #5542 Sorting by name #5550
Conversation
Thanks for offering @bernardo-campos, but I'm not too keen on us having diverging logic for minor functionality depending on available extensions. I'd also be concerned about the use of locale, since the user locale isn't assured to match the content and I don't want sort logic to change depending on user performing the action which causes changes. The codebase already uses the https://github.com/voku/portable-ascii library via Laravel, could we maybe use the Also, it would be good to have some added tests to cover this scenario, similar to our existing name sort tests: BookStack/tests/Sorting/SortRuleTest.php Line 190 in 13dae24
|
Ok. I see the point. Yep, using |
0a2d80f
to
abe7467
Compare
I’ve changed: I know the logic got a bit lengthy, but I realized that just using Another idea is to use laravel helper |
Thanks @bernardo-campos, although I think we'd want to specifically pass in
That would lead to a bit too much conversion of the original text, similar to what I mention above, which would lead to less stable/expected sorting outcomes. |
Thanks again @bernardo-campos, I followed this up with 1ba0d26 to address my comment above. |
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.