Skip to content

Commit 16e9af8

Browse files
author
Vladimir Kotal
authored
Merge pull request #1234 from tulinkry/tablesorter-fix
making tablesorter size parser more robust
2 parents 061639f + 96b9d8e commit 16e9af8

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

web/js/tablesorter.parsers.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,32 @@ $.tablesorter.addParser({
4545
return false;
4646
},
4747
format: function (s) {
48-
var parts = s.match(/^([\d\.]+) ?(\w*)$/);
49-
var num = parts[1];
48+
/*
49+
* This correctly handles thousand separator
50+
* in a big number (either ',' or ' ' or none)
51+
*
52+
* In our case there is a little gap between 1000 and 1023 which
53+
* is still smaller than the next order unit. This should accept all
54+
* values like:
55+
* 1,000 or 1 000 or 1,023
56+
*
57+
* However it is more generic just in case. It should not have trouble
58+
* with:
59+
* 1,000,123,133.235
60+
* 1 000.4564
61+
* and with even mispelled numbers:
62+
* 1,00,345,0.123 (wrong number of digits between the separator)
63+
* 13,456 13 45.1234 (mixed separators)
64+
* 1000,123 (wrong number of digits between the separator)
65+
* 1,123534435,134547435.165165165 (again)
66+
*/
67+
var parts = s.match(/^(\d{1,3}(?:[, ]?\d{1,3})*(?:\.\d+)?|\.\d+) ?(\w*)$/);
68+
69+
if (parts === null || parts.length < 3) {
70+
return 0;
71+
}
72+
73+
var num = parts[1].replace(/[, ]/g, "")
5074
var unit = parts[2];
5175

5276
// convert to bytes

0 commit comments

Comments
 (0)