From: Derk-Jan Hartman Date: Fri, 30 Dec 2016 13:10:32 +0000 (+0100) Subject: jquery.tablesorter: Sort invalid elements as -Infinity X-Git-Tag: 1.31.0-rc.0~4433^2 X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=commitdiff_plain;h=ea0f879b32a9f0e77e74d7977b17e763afd27deb;p=lhc%2Fweb%2Fwiklou.git jquery.tablesorter: Sort invalid elements as -Infinity NaN is problematic when sorting. We used 0 before, but that means that these items get mixed in between 0 elements or in the middle of a column when it has both negative and positive numbers. Therefore sort as -Infinity instead, which is a proper number and will always sort to the edge. Bug: T154307 Change-Id: I4837669205a6c6d470f19b26d721efd2ccdcc3a0 --- diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index 4da05e63ef..1b64237d07 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -1018,17 +1018,17 @@ s = out; } i = parseFloat( s.replace( /[, ]/g, '' ).replace( '\u2212', '-' ) ); - return isNaN( i ) ? 0 : i; + return isNaN( i ) ? -Infinity : i; }, formatFloat: function ( s ) { var i = parseFloat( s ); - return isNaN( i ) ? 0 : i; + return isNaN( i ) ? -Infinity : i; }, formatInt: function ( s ) { var i = parseInt( s, 10 ); - return isNaN( i ) ? 0 : i; + return isNaN( i ) ? -Infinity : i; }, clearTableBody: function ( table ) { diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js index 11ceeea2fc..5203def852 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.parsers.test.js @@ -88,7 +88,7 @@ [ '1.238.27.1', true, 1238027001, 'An IP address with small numbers' ], [ '238.27.1', false, 238027001, 'A malformed IP Address' ], [ '1', false, 1, 'A super malformed IP Address' ], - [ 'Just text', false, 0, 'A line with just text' ], + [ 'Just text', false, -Infinity, 'A line with just text' ], [ '45.238.27.109Postfix', false, 45238027109, 'An IP address with a connected postfix' ], [ '45.238.27.109 postfix', false, 45238027109, 'An IP address with a seperated postfix' ] ]; @@ -177,22 +177,22 @@ [ '2000', false, 0, 'Plain 4-digit year' ], [ '2000-01', false, 0, 'Year with month' ], [ '2000-01-01', true, 946684800000, 'Year with month and day' ], - [ '2000-13-01', true, 0, 'Non existant month' ], - [ '2000-01-32', true, 0, 'Non existant day' ], + [ '2000-13-01', true, -Infinity, 'Non existant month' ], + [ '2000-01-32', true, -Infinity, 'Non existant day' ], [ '2000-01-01T12:30:30', true, 946729830000, 'Date with a time' ], [ '2000-01-01T12:30:30Z', true, 946729830000, 'Date with a UTC+0 time' ], - [ '2000-01-01T24:30:30Z', true, 0, 'Date with invalid hours' ], - [ '2000-01-01T12:60:30Z', true, 0, 'Date with invalid minutes' ], + [ '2000-01-01T24:30:30Z', true, -Infinity, 'Date with invalid hours' ], + [ '2000-01-01T12:60:30Z', true, -Infinity, 'Date with invalid minutes' ], [ '2000-01-01T12:30:61Z', true, 946729800000, 'Date with invalid amount of seconds, drops seconds' ], [ '2000-01-01T23:59:59Z', true, 946771199000, 'Edges of time' ], [ '2000-01-01T12:30:30.111Z', true, 946729830111, 'Date with milliseconds' ], [ '2000-01-01T12:30:30.11111Z', true, 946729830111, 'Date with too high precision' ], - [ '2000-01-01T12:30:30,111Z', true, 0, 'Date with milliseconds and , separator' ], + [ '2000-01-01T12:30:30,111Z', true, -Infinity, 'Date with milliseconds and , separator' ], [ '2000-01-01T12:30:30+01:00', true, 946726230000, 'Date time in UTC+1' ], [ '2000-01-01T12:30:30+01:30', true, 946724430000, 'Date time in UTC+1:30' ], [ '2000-01-01T12:30:30-01:00', true, 946733430000, 'Date time in UTC-1' ], [ '2000-01-01T12:30:30-01:30', true, 946735230000, 'Date time in UTC-1:30' ], - [ '2000-01-01T12:30:30.111+01:00', true, 946726230111, 'Date time and milliseconds in UTC+1 ' ], + [ '2000-01-01T12:30:30.111+01:00', true, 946726230111, 'Date time and milliseconds in UTC+1' ], [ '2000-01-01Postfix', true, 946684800000, 'Date with appended postfix' ], [ '2000-01-01 Postfix', true, 946684800000, 'Date with separate postfix' ] /* Disable testcases, because behavior is browser dependant */ diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index ca26aaf904..483a37d1be 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -1454,8 +1454,8 @@ assert.equal( parsers[ 1 ].format( $table.find( 'tbody > tr > td:eq(1)' ).text() ), - 0, - 'empty cell is sorted as number 0' + -Infinity, + 'empty cell is sorted as number -Infinity' ); } );