https://bugzilla.wikimedia.org/show_bug.cgi?id=17139

           Summary: ts_resortTable inconsistent trimming makes date sorting
                    fragile
           Product: MediaWiki
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: easy
          Severity: normal
          Priority: Normal
         Component: Page rendering
        AssignedTo: [email protected]
        ReportedBy: [email protected]


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]+$/,"");


-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to