Use ECMAScript standard, section 9.3, to decide what's a number
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 3 Sep 2008 13:45:10 +0000 (13:45 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 3 Sep 2008 13:45:10 +0000 (13:45 +0000)
r40348 was kind of broken, in terms of considering strings like "e" to be numbers.  The version before that would also act incorrectly for strings like ".".

skins/common/wikibits.js

index 9a5dc13..fa6fe83 100644 (file)
@@ -616,7 +616,11 @@ function ts_resortTable(lnk) {
        // pound dollar euro yen currency cents
        else if (itm.match(/(^[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/))
                sortfn = ts_sort_currency;
-       else if (itm.match(/^[\d.,eE+-]+\%?$/))
+       // We allow a trailing percent sign, which we just strip.  This works fine
+       // if percents and regular numbers aren't being mixed.
+       else if (itm.match(/^[+-]?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?\%?$/) ||
+       itm.match(/^[+-]?\.[0-9]+([eE][+-]?[0-9]+)?\%?$/) ||
+       itm.match(/^0[xX][0-9a-fA-F]+$/))
                sortfn = ts_sort_numeric;
 
        var reverse = (span.getAttribute("sortdir") == 'down');