Page MenuHomePhabricator

Tablesorter should handle <br> as spaces in sort values
Closed, ResolvedPublicBUG REPORT

Description

Following up to an issue reported on frwiki here (and here).

A cell that contains this:

<time … data-sort-value="1840">1840</time><br><time … data-sort-value="1889">1889</time>

Ends up with this sort value: 18401889.

The issue has been fixed locally by adding a space next to the <br> tag:

<time … data-sort-value="1840">1840</time> <br><time … data-sort-value="1889">1889</time>

So the sort value has become: 1840 1889.

An improvement in Tablesorter, when parsing the nodes to build the sort value, would be to replace the <br> tags with a space, rather than an empty string. See the code here.

Also, we may want to normalize and remove the consecutive spaces, by adding something like result.replace( /\s+/g, ' ' ). (edit: created T326474 for this)

Event Timeline

Also, we may want to normalize and remove the consecutive spaces, by adding something like result.replace( /\s+/g, ' ' ).

Ideally, we should normalize as HTML does, i.e. remove consecutive spaces in text nodes, between nodes… but not in data-sort-value attributes.

If I use data-sort-value="foo bar" in wikicode, the HTML output is data-sort-value="foo bar".

As the wikicode parser has normalized these spaces beforehand, it would be pointless to try to preserve them when building the sort value afterwards.

Also, I doubt users would want to use consecutive spaces to tweak the sort order…

Change 876313 had a related patch set uploaded (by Gerrit Patch Uploader; author: Hank Hulet):

[mediawiki/core@master] Replace <br> with space rather than empty string when building the sort key

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

Change 876313 merged by jenkins-bot:

[mediawiki/core@master] Replace <br> with space rather than empty string when building the sort key

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

matmarex subscribed.

The patch was sent by "Hank Hulet", I couldn't find their Phabricator account. Thanks!