Page MenuHomePhabricator

Tablesorter does not autorecognise numbers if non-breaking space is used as thousands separator
Closed, ResolvedPublicBUG REPORT

Description

The Swedish number format as used by {{formatnum:}} contains a non breaking space as thousands separator. This is correctly sorted by the table sorter when data-sort-type=number. Without data-sort-type this used to be autodetected as numbers and sorted correctly. But I think something was changed recently. Now without data-sort-type the column is sorted as text, even if it only contains formatted numbers.

Example:
In a Swedish language wiki (e.g. sv.wikipedia.org)

{| class="sortable wikitable"
! data-sort-type="number" | type=number<br> sorts correctly
! no type<br>sorts as text
! no type<br>sorts as number
|-
| {{formatnum:4000}} || {{formatnum:4000}} || {{formatnum:400}}
|-
| {{formatnum:3.9}}  || {{formatnum:3.9}}  || {{formatnum:3.9}}
|-
| {{formatnum:4.12}} || {{formatnum:4.12}} || {{formatnum:4.12}}
|-
| {{formatnum:4.2}}  || {{formatnum:4.2}}  || {{formatnum:4.2}}
|}
  1. The first column with data-sort-type sorts as expected.
  2. The second column with thousands separators and without data-sort-type is not autodetected as number and sorts as text. Thousands separator and decimal commas are not recognised as numbers. Sorts 4,2 incorrectly before 4,12.
  3. The third column without thousands separators and without data-sort-type is autodetected and sorted as numbers. Correctly sorts 4,2 after 4,12.

Expected results would be that all columns with only formatted numbers are autorecognised as numbers.

Event Timeline

Daimona renamed this task from Tablesorter does not autorecognise swedish thousands separator as number to Tablesorter does not autorecognise numbers if non-breaking space is used as thousands separator.Feb 17 2023, 6:39 PM

I've seen the same problem on itwiki, and Italian uses a non-breaking space as thousands separator, too. In fact, this affects a lot of languages, based on a quick look at the values of $separatorTransformTable.

Daimona triaged this task as High priority.Feb 17 2023, 6:59 PM

A quick git blame points to r876314. Also, I'm setting the priority to high because sorting is broken for all number columns in all languages that use nbsp as the thousands separator, which seems quite serious.

Change 890015 had a related patch set uploaded (by Daimona Eaytoy; author: Daimona Eaytoy):

[mediawiki/core@master] Do not replace all whitespace characters with space in tablesorter

https://gerrit.wikimedia.org/r/890015

Change 890015 merged by jenkins-bot:

[mediawiki/core@master] Do not replace all whitespace characters with space in tablesorter

https://gerrit.wikimedia.org/r/890015