Add support to tablesorter to handle IP/CIDR notation
authorDerk-Jan Hartman <hartman@users.mediawiki.org>
Sat, 18 Feb 2012 14:35:14 +0000 (14:35 +0000)
committerDerk-Jan Hartman <hartman@users.mediawiki.org>
Sat, 18 Feb 2012 14:35:14 +0000 (14:35 +0000)
This fixes bug 34475

RELEASE-NOTES-1.20
resources/jquery/jquery.tablesorter.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

index 5090672..aa5edcb 100644 (file)
@@ -19,6 +19,7 @@ production.
   preference for the non-default skin to look at something using the default skin.
 * (bug 31417) New ID mw-content-text around the actual page text, without categories,
   contentSub, ... The same div often also contains the class mw-content-ltr/rtl.
+* (bug 34475) Add support for IP/CIDR notation to tablesorter
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index ea86b64..ca9971b 100644 (file)
                }
                ts.rgx = {
                        IPAddress: [
-                               new RegExp( /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/)
+                               new RegExp( /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}(\/\d{1,3})?$/)
                        ],
                        currency: [
                                new RegExp( /^[£$€?.]/),
                },
                format: function( s ) {
                        var     a = s.split( '.' ),
-                               r = '',
-                               l = a.length;
-                       for ( var i = 0; i < l; i++ ) {
+                               r = '';
+                       if( a.length == 4 ) {
+                               var cidr = a[3].split('/');
+                               if (cidr.length > 1 ) {
+                                       a[3] = cidr[0];
+                                       a[4] = cidr[1];
+                               } else a[4] = '000';
+                       }
+                       for ( var i = 0; i < a.length; i++ ) {
                                var item = a[i];
                                if ( item.length == 1 ) {
                                        r += '00' + item;
index 95284c7..ec34102 100644 (file)
@@ -236,6 +236,38 @@ var ipv4Sorted = [
        ['204.204.132.158'],
        ['247.240.82.209']
 ];
+var ipv4CIDR = [
+       // Some randomly generated fake IPs
+       ['45.238.27.109/36'],
+       ['170.38.91.162/36'],
+       ['247.240.82.209/36'],
+       ['204.204.132.158/24'],
+       ['170.38.91.162/24']
+];
+var ipv4CIDRSorted = [
+       // Sort order should go octet by octet
+       ['45.238.27.109/36'],
+       ['170.38.91.162/24'],
+       ['170.38.91.162/36'],
+       ['204.204.132.158/24'],
+       ['247.240.82.209/36']
+];
+var ipv4Mixed = [
+       // Some randomly generated fake IPs
+       ['45.238.27.109'],
+       ['170.38.91.162'],
+       ['247.240.82.209'],
+       ['204.204.132.158/24'],
+       ['170.38.91.162/24']
+];
+var ipv4MixedSorted = [
+       // Sort order should go octet by octet
+       ['45.238.27.109'],
+       ['170.38.91.162'],
+       ['170.38.91.162/24'],
+       ['204.204.132.158/24'],
+       ['247.240.82.209']
+];
 
 tableTest(
        'Bug 17141: IPv4 address sorting',
@@ -257,6 +289,27 @@ tableTest(
                $table.find( '.headerSort:eq(0)' ).click().click();
        }
 );
+tableTest(
+       'Bug 34475: IPv4/CIDR address sorting',
+       ['IP'],
+       ipv4CIDR,
+       ipv4CIDRSorted,
+       function( $table ) {
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+       }
+);
+
+tableTest(
+       'Bug 34475: Mixed IPv4 and IP/CIDR address sorting',
+       ['IP'],
+       ipv4Mixed,
+       ipv4MixedSorted,
+       function( $table ) {
+               $table.tablesorter();
+               $table.find( '.headerSort:eq(0)' ).click();
+       }
+);
 
 var umlautWords = [
        // Some words with Umlauts