Author: henry.ayoola
Description:
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]+$/,"");
Version: unspecified
Severity: normal