Last modified: 2011-01-25 01:01:56 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 17139 - ts_resortTable inconsistent trimming makes date sorting fragile
ts_resortTable inconsistent trimming makes date sorting fragile
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Brion Vibber
: easy
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-01-23 20:27 UTC by henry.ayoola
Modified: 2011-01-25 01:01 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description henry.ayoola 2009-01-23 20:27:32 UTC
In file http://images.wikia.com/common/releases_200901.4/skins/monobook/allinone.js?5134 ts_resortTable does a trim:

itm=itm.replace(/^[\s\xa0]+/,"").replace(/[\s\xa0]+$/,"");

before using itm to work out which comparison function to use. However, it doesn't then trim the keyText when building the array to sort, and nor does ts_dateToSortKey.

Consider the simple table


{| class="wikitable sortable"
! Date || Event
|-
| 01 Apr 2000 || Something happened
|-
| 02 Apr 2000 || Something else happened
|}


This will result in table data cells with spaces:


<table class="wikitable sortable">

<tr>
<th> Date </th><th> Event
</th></tr>
<tr>
<td> 01 Apr 2000 </td><td> Something happened
</td></tr>
<tr>
<td> 02 Apr 2000 </td><td> Something else happened

</td></tr></table>


Because of the trim, ts_resortTable will detect that the first column contains a date, but when ts_datetoSortKey is passed ' 01 Apr 2000 ', of length 13 characters, it will fail to match any of the three known formats and so the sort key will be "00000000". As a result attempting to sort by the first column won't change the order at all (stable sort and every row generates the same sort key).

The result is that sorting is very fragile. The simple fix is to append after the line

var keyText=ts_getInnerText(row.cells[column]);

a further line

keyText=keyText.replace(/^[\s\xa0]+/,"").replace(/[\s\xa0]+$/,"");
Comment 1 David Griffiths 2009-02-07 08:27:08 UTC
Was just about to open this same issue when I came across this. BTW my fix was to add this as the first line of ts_dateToSortKey:

date = date.replace(/^\s+|\s+$/g,"");   // trim white space

Oh, just noticed that this is reported against a different file. My issue was in skins/common/wikibits.js.
Comment 2 Brion Vibber 2009-07-19 21:15:14 UTC
Confirmed with $wgUseTidy off. Peeking...
Comment 3 Brion Vibber 2009-07-19 21:26:16 UTC
Done in r53495 -- added the trim on the sort key preprocessor call as well as the selection.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links