Skip to content

Sorting by name not working with "É" #5542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serinf-lauza opened this issue Mar 18, 2025 · 2 comments
Closed

Sorting by name not working with "É" #5542

serinf-lauza opened this issue Mar 18, 2025 · 2 comments
Labels
Milestone

Comments

@serinf-lauza
Copy link

serinf-lauza commented Mar 18, 2025

Describe the Bug

Hi! I created a sorting rule that only has Name - Alphabetical (Asc) in it. When I apply it to a book, the letter "É" gets sort out at the end of everything. It should be between "D" and "F", the previous method for sorting by name still works and put it as it's rightful place (Sort by name). My BookStack is in French, so we use a lot of "É" in our titles!
Thank you! :)

Steps to Reproduce

  1. Settings > Sorting
  2. Create a rule with Name - Alphabetical (Asc)
  3. Choose the Auto sort Option created previously to sort a chapter
  4. See where "É" goes

Image

Expected Behaviour

It should be between "D" and "F" when sorted by name.

Screenshots or Additional Context

No response

Browser Details

Chrome

Exact BookStack Version

v25.02.1

@bernardo-campos
Copy link
Contributor

In BookStack\Sorting\SortSetOperationComparisons, the nameAsc and nameDesc functions use:

return strtolower($a->name) <=> strtolower($b->name);

The <=> operator combined with strtolower() doesn’t reliably handle accented characters across all configurations. For example, it might sort "é" after "z" leading to inconsistent results in languages like Spanish or French.

Using Collator from the intl extension would be more appropriate, as it offers locale-aware comparisons for accurate and culturally correct sorting of accented characters.

I’m working on a PR to address this.

bernardo-campos added a commit to bernardo-campos/BookStack that referenced this issue Mar 23, 2025
Replace <=> with Collator for better accented character handling
Using <=> with strtolower() can misorder accented characters (e.g., "é" after "z"), making it less reliable for some languages. Collator from intl ensures precise, locale-aware string comparisons.
bernardo-campos added a commit to bernardo-campos/BookStack that referenced this issue Mar 23, 2025
@ssddanbrown ssddanbrown added this to the v25.02.2 milestone Mar 24, 2025
@ssddanbrown
Copy link
Member

Thanks to the work done by @bernardo-campos in #5550 this has now been improved, with the applied changes due to be part of the next patch release.

Thanks @serinf-lauza for raising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants