http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90637

Revision: 90637
Author:   brion
Date:     2011-06-23 00:37:23 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/phase3/resources/jquery/jquery.tablesorter.js
    trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

Modified: trunk/phase3/resources/jquery/jquery.tablesorter.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.tablesorter.js 2011-06-22 23:49:16 UTC 
(rev 90636)
+++ trunk/phase3/resources/jquery/jquery.tablesorter.js 2011-06-23 00:37:23 UTC 
(rev 90637)
@@ -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;

Modified: 
trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
===================================================================
--- trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js 
2011-06-22 23:49:16 UTC (rev 90636)
+++ trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js 
2011-06-23 00:37:23 UTC (rev 90637)
@@ -212,4 +212,47 @@
        }
 );
 
+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();
+       }
+);
+
 })();


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to