Added port to IPV4 sorting and reduced if/else chains

The original method of extracting the IP address from an IP:PORT pair never re-applied the PORT number to the sorting algorithm.
This commit has added the functionality for the port number to be included in the sorting for IPv4 if it existed in the original value by appending it to the final zero-filled IPv4 address string.
This commit also reduces the number of if/else chains to perform the zerofill by using a substr of a zeroed pattern matching the desired size of the field. "000" for IPv4 octets, "0000" for IPv6, and "00000" for port numbers.
pull/532/head
Kevin Gilkey-Graham 3 years ago committed by GitHub
parent fc25f864c9
commit 0688007640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@
* @author Dominique Fournier * @author Dominique Fournier
* @author Brad Wasson * @author Brad Wasson
* @author Peter Vilhan * @author Peter Vilhan
* @author Kevin Gilkey-Graham
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {
@ -21,7 +22,7 @@
jQuery.extend( jQuery.fn.dataTableExt.oSort, { jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"ip-address-pre": function ( a ) { "ip-address-pre": function ( a ) {
var i, item; var i, item;
var m, n, t; var m, n, t, p;
var x, xa; var x, xa;
if (!a) { if (!a) {
@ -33,6 +34,7 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
t = a.split(":"); t = a.split(":");
if (t.length == 2){ if (t.length == 2){
m = t[0].split("."); m = t[0].split(".");
p = t[1];
} }
else { else {
m = a.split("."); m = a.split(".");
@ -45,16 +47,10 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
// IPV4 // IPV4
for(i = 0; i < m.length; i++) { for(i = 0; i < m.length; i++) {
item = m[i]; item = m[i];
x += "000".substr(item.length) + item;
if(item.length == 1) { }
x += "00" + item; if (p) {
} x += ":" + "00000".substr(p.length) + p;
else if(item.length == 2) {
x += "0" + item;
}
else {
x += item;
}
} }
} }
else if (n.length > 0) { else if (n.length > 0) {
@ -70,20 +66,8 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
if(item.length === 0) { if(item.length === 0) {
count += 0; count += 0;
} }
else if(item.length == 1) {
xa += "000" + item;
count += 4;
}
else if(item.length == 2) {
xa += "00" + item;
count += 4;
}
else if(item.length == 3) {
xa += "0" + item;
count += 4;
}
else { else {
xa += item; xa += "0000".substr(item.length) + item;
count += 4; count += 4;
} }
} }

Loading…
Cancel
Save