From f2ff5d901af621944c7aa9c8325a5ec6fcd148cf Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 23 Jun 2011 00:37:23 +0000 Subject: [PATCH] Followup r86088: test cases and a correction for bug 17141 (IPv4 address sorting) Test lists 8 randomly generated IPv4 addresses and attempts to sort them both forward and back. Turned up a bug where single-digit octets (eg a .1 or .9) were not expanded in the sort key, causing them to mis-sort. --- resources/jquery/jquery.tablesorter.js | 4 +- .../jquery/jquery.tablesorter.test.js | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 821d9acb06..3ce4c66c1f 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -726,7 +726,9 @@ l = a.length; for ( var i = 0; i < l; i++ ) { var item = a[i]; - if ( item.length == 2 ) { + if ( item.length == 1 ) { + r += "00" + item; + } else if ( item.length == 2 ) { r += "0" + item; } else { r += item; diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index 1289e95180..385d98a89c 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -212,4 +212,47 @@ tableTest( } ); +var ipv4 = [ + // Some randomly generated fake IPs + ['45.238.27.109'], + ['44.172.9.22'], + ['247.240.82.209'], + ['204.204.132.158'], + ['170.38.91.162'], + ['197.219.164.9'], + ['45.68.154.72'], + ['182.195.149.80'] +]; +var ipv4Sorted = [ + // Sort order should go octet by octet + ['44.172.9.22'], + ['45.68.154.72'], + ['45.238.27.109'], + ['170.38.91.162'], + ['182.195.149.80'], + ['197.219.164.9'], + ['204.204.132.158'], + ['247.240.82.209'] +]; +tableTest( + 'Bug 17141: IPv4 address sorting', + ['IP'], + ipv4, + ipv4Sorted, + function( $table ) { + $table.tablesorter(); + $table.find('.headerSort:eq(0)').click(); + } +); +tableTest( + 'Bug 17141: IPv4 address sorting (reverse)', + ['IP'], + ipv4, + reversed(ipv4Sorted), + function( $table ) { + $table.tablesorter(); + $table.find('.headerSort:eq(0)').click().click(); + } +); + })(); -- 2.20.1