[PR #5550] [MERGED] Fix issue #5542 Sorting by name #6520

Closed
opened 2026-02-05 10:34:31 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/BookStackApp/BookStack/pull/5550
Author: @bernardo-campos
Created: 3/23/2025
Status: Merged
Merged: 4/2/2025
Merged by: @ssddanbrown

Base: developmentHead: development


📝 Commits (1)

  • abe7467 Fix issue BookStackApp#5542 Sorting by name

📊 Changes

2 files changed (+5 additions, -2 deletions)

View changed files

📝 app/Sorting/SortSetOperationComparisons.php (+3 -2)
📝 tests/Sorting/SortRuleTest.php (+2 -0)

📄 Description

Related Issue: Issue #5542

Summary:

Replaces the <=> operator with PHP’s Collator class for locale-aware string comparisons in App\Sorting\SortSetOperationComparisons. Using <=> with strtolower() 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

 protected static function getCollator(): ?\Collator
 {
    $locale = user()->getLocale()->isoLocale(); // e.g., 'eu_ES', 'fr_FR'
    return class_exists(\Collator::class) ? collator_create($locale) : null;
}
  • $locale is fetched from the user’s settings via BookStack\Translation\LocaleManager.
  • class_exists(\Collator::class) checks for the intl extension, returning null if unavailable (graceful fallback).
  • The returned Collator object (or null) is used in the class’s comparison functions to handle sorting.

Impact:

  • Improves sorting for users with locales like fr_FR or eu_ES.
  • No breaking changes; users without intl fall back to existing behavior.

TL;DR: Swaps <=> for Collator to fix accented character sorting, with a fallback for missing intl.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/BookStackApp/BookStack/pull/5550 **Author:** [@bernardo-campos](https://github.com/bernardo-campos) **Created:** 3/23/2025 **Status:** ✅ Merged **Merged:** 4/2/2025 **Merged by:** [@ssddanbrown](https://github.com/ssddanbrown) **Base:** `development` ← **Head:** `development` --- ### 📝 Commits (1) - [`abe7467`](https://github.com/BookStackApp/BookStack/commit/abe7467ae5f9341f2f5f9cad3b1a48724ed1a425) Fix issue BookStackApp#5542 Sorting by name ### 📊 Changes **2 files changed** (+5 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `app/Sorting/SortSetOperationComparisons.php` (+3 -2) 📝 `tests/Sorting/SortRuleTest.php` (+2 -0) </details> ### 📄 Description Related Issue: [Issue #5542](https://github.com/BookStackApp/BookStack/issues/5542) **Summary:** Replaces the `<=>` operator with PHP’s Collator class for locale-aware string comparisons in `App\Sorting\SortSetOperationComparisons`. Using `<=>` with `strtolower()` 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 ``` protected static function getCollator(): ?\Collator { $locale = user()->getLocale()->isoLocale(); // e.g., 'eu_ES', 'fr_FR' return class_exists(\Collator::class) ? collator_create($locale) : null; } ``` - `$locale` is fetched from the user’s settings via `BookStack\Translation\LocaleManager`. - `class_exists(\Collator::class)` checks for the **intl extension**, returning `null` if unavailable (graceful fallback). - The returned `Collator` object (or `null`) is used in the class’s comparison functions to handle sorting. **Impact:** - Improves sorting for users with locales like fr_FR or eu_ES. - No breaking changes; users without intl fall back to existing behavior. **TL;DR:** Swaps <=> for Collator to fix accented character sorting, with a fallback for missing intl. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 10:34:31 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#6520