mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Parser: Network parsers now return a text value. Fixes #1494
This commit is contained in:
parent
b325235fc1
commit
c9e93cc7f1
@ -48,11 +48,13 @@
|
|||||||
<em>NOTE!</em>
|
<em>NOTE!</em>
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="label warning">NOTE</span> The default "ipAddress" parser (also named "ipv4Address") is included with the original tablesorter; it was moved to the <code>parser-network.js</code> file in <span class="version">v2.18.0</span>.</li>
|
<li><span class="label warning">NOTE</span> The default "ipAddress" parser (also named "ipv4Address") is included with the original tablesorter; it was moved to the <code>parser-network.js</code> file in <span class="version">v2.18.0</span>.<br><br></li>
|
||||||
|
|
||||||
|
<li>In <span class="version">v2.29.3</span>, all included parsers were changed to return a text representation of the network address. The specific issue was that the parsed IPv6 numerical values were too large for javascript to properly recognize the number.</li>
|
||||||
<li>A parser for IPv6 was added in <span class="version">v2.12</span> and named "ipv6Address":
|
<li>A parser for IPv6 was added in <span class="version">v2.12</span> and named "ipv6Address":
|
||||||
<ul>
|
<ul>
|
||||||
<li>Unlike some other custom parsers, this one will auto-detect & check for a valid IPv6 address since the same address can be represented in many different ways. Some examples are shown in the demo table below.</li>
|
<li>Unlike some other custom parsers, this one will auto-detect & check for a valid IPv6 address since the same address can be represented in many different ways. Some examples are shown in the demo table below.</li>
|
||||||
<li>IPv6 addresses are stored in the cache in their canonical decimal form, without the colons, for faster & easier numerical sorting.</li>
|
<li>IPv6 addresses are stored in the cache in their canonical decimal form, for faster & easier numerical sorting.</li>
|
||||||
<li><a href="../test.html">Extensive unit tests</a> are included with this parser.</li>
|
<li><a href="../test.html">Extensive unit tests</a> are included with this parser.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*! Parser: network - updated 5/17/2015 (v2.22.0) */
|
/*! Parser: network - updated 2018-01-10 (v2.29.3) */
|
||||||
/* IPv4, IPv6 and MAC Addresses */
|
/* IPv4, IPv6 and MAC Addresses */
|
||||||
/*global jQuery: false */
|
/*global jQuery: false */
|
||||||
;(function($){
|
;(function($){
|
||||||
@ -23,6 +23,10 @@
|
|||||||
ipv6Validate : /^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/i
|
ipv6Validate : /^\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/i
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// used for internal testing; it's not useful to set this to true because the natural sort algorithm
|
||||||
|
// is set up to only sort solitary hex values ("ffff") vs separated hex values ("ffff.ffff")
|
||||||
|
ts.defaults.ipv6HexFormat = false;
|
||||||
|
|
||||||
ts.addParser({
|
ts.addParser({
|
||||||
id: 'ipv6Address',
|
id: 'ipv6Address',
|
||||||
is: function(s) {
|
is: function(s) {
|
||||||
@ -72,10 +76,10 @@
|
|||||||
('00000' + (parseInt(groups[i], 16) || 0)).slice(-5);
|
('00000' + (parseInt(groups[i], 16) || 0)).slice(-5);
|
||||||
expandedAddress += ( i != validGroupCount - 1) ? groups[i] + ':' : groups[i];
|
expandedAddress += ( i != validGroupCount - 1) ? groups[i] + ':' : groups[i];
|
||||||
}
|
}
|
||||||
return hex ? expandedAddress : expandedAddress.replace(/:/g, '');
|
return expandedAddress;
|
||||||
},
|
},
|
||||||
// uses natural sort hex compare
|
// uses natural sort hex compare
|
||||||
type: 'numeric'
|
type: 'text'
|
||||||
});
|
});
|
||||||
|
|
||||||
// ipv4 address
|
// ipv4 address
|
||||||
@ -83,14 +87,15 @@
|
|||||||
ipv4Is = function(s) {
|
ipv4Is = function(s) {
|
||||||
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
|
return (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/).test(s);
|
||||||
};
|
};
|
||||||
ipv4Format = function(s, table) {
|
ipv4Format = function(s) {
|
||||||
var i, a = s ? s.split('.') : '',
|
var i,
|
||||||
r = '',
|
a = s ? s.split('.') : '',
|
||||||
|
r = [],
|
||||||
l = a.length;
|
l = a.length;
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
r += ('000' + a[i]).slice(-3);
|
r.push(('000' + a[i]).slice(-3));
|
||||||
}
|
}
|
||||||
return s ? ts.formatFloat(r, table) : s;
|
return s ? r.join('.') : s;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Parser: ipv4Address (a.k.a. ipAddress) */
|
/*! Parser: ipv4Address (a.k.a. ipAddress) */
|
||||||
@ -99,13 +104,13 @@
|
|||||||
id: 'ipAddress',
|
id: 'ipAddress',
|
||||||
is: ipv4Is,
|
is: ipv4Is,
|
||||||
format: ipv4Format,
|
format: ipv4Format,
|
||||||
type: 'numeric'
|
type: 'text'
|
||||||
});
|
});
|
||||||
ts.addParser({
|
ts.addParser({
|
||||||
id: 'ipv4Address',
|
id: 'ipv4Address',
|
||||||
is: ipv4Is,
|
is: ipv4Is,
|
||||||
format: ipv4Format,
|
format: ipv4Format,
|
||||||
type: 'numeric'
|
type: 'text'
|
||||||
});
|
});
|
||||||
|
|
||||||
/*! Parser: MAC address */
|
/*! Parser: MAC address */
|
||||||
@ -118,21 +123,21 @@
|
|||||||
},
|
},
|
||||||
format : function( str ) {
|
format : function( str ) {
|
||||||
var indx, len,
|
var indx, len,
|
||||||
mac = '',
|
mac = [],
|
||||||
val = ( str || '' ).replace( /[:.-]/g, '' ).match( /\w{2}/g );
|
val = ( str || '' ).replace( /[:.-]/g, '' ).match( /\w{2}/g );
|
||||||
if ( val ) {
|
if ( val ) {
|
||||||
// not assuming all mac addresses in the column will end up with six
|
// not assuming all mac addresses in the column will end up with six
|
||||||
// groups of two to process, so it's not actually validating the address
|
// groups of two to process, so it's not actually validating the address
|
||||||
len = val.length;
|
len = val.length;
|
||||||
for ( indx = 0; indx < len; indx++ ) {
|
for ( indx = 0; indx < len; indx++ ) {
|
||||||
mac += ( '000' + parseInt( val[ indx ], 16 ) ).slice( -3 );
|
mac.push(( '000' + parseInt( val[ indx ], 16 ) ).slice( -3 ));
|
||||||
}
|
}
|
||||||
return mac;
|
return mac.join('.');
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
// uses natural sort hex compare
|
// uses natural sort hex compare
|
||||||
type : 'numeric'
|
type : 'text'
|
||||||
});
|
});
|
||||||
|
|
||||||
})( jQuery );
|
})( jQuery );
|
||||||
|
@ -489,7 +489,7 @@ jQuery(function($){
|
|||||||
sample1 = {
|
sample1 = {
|
||||||
'text' : { 'test': 'test', 'TesT': 'test', '\u00e1 test': '\u00e1 test' },
|
'text' : { 'test': 'test', 'TesT': 'test', '\u00e1 test': '\u00e1 test' },
|
||||||
'currency' : { '\u00a31': 1, '($2.23)': -2.23, '5\u20ac': 5, '(11\u00a4)': -11, '500\u00a5': 500, '25\u00a2': 25, '$1,000.50': 1000.5 },
|
'currency' : { '\u00a31': 1, '($2.23)': -2.23, '5\u20ac': 5, '(11\u00a4)': -11, '500\u00a5': 500, '25\u00a2': 25, '$1,000.50': 1000.5 },
|
||||||
'ipAddress' : { '255.255.255.255': 255255255255, '32.32.32.32': 32032032032, '1.1.1.1': 1001001001 },
|
'ipAddress' : { '255.255.255.255': '255.255.255.255', '32.32.32.32': '032.032.032.032', '1.1.1.1': '001.001.001.001' },
|
||||||
'url' : { 'http://google.com': 'google.com', 'ftp://fred.com': 'fred.com', 'https://github.com': 'github.com' },
|
'url' : { 'http://google.com': 'google.com', 'ftp://fred.com': 'fred.com', 'https://github.com': 'github.com' },
|
||||||
'isoDate' : { '2012/12/12': returnTime('2012/12/12'), '2012-12/12': returnTime('2012/12/12'), '2013-1-1': returnTime('2013/1/1'), '2013/1/1 12:34:56 AM': returnTime('2013/1/1 12:34:56 AM') },
|
'isoDate' : { '2012/12/12': returnTime('2012/12/12'), '2012-12/12': returnTime('2012/12/12'), '2013-1-1': returnTime('2013/1/1'), '2013/1/1 12:34:56 AM': returnTime('2013/1/1 12:34:56 AM') },
|
||||||
'percent' : { '100%': 100, '22%': 22, '%2': 2, '2 %': 2, '(4%)': -4, '1,234.56 %': 1234.56 },
|
'percent' : { '100%': 100, '22%': 22, '%2': 2, '2 %': 2, '(4%)': -4, '1,234.56 %': 1234.56 },
|
||||||
|
Loading…
Reference in New Issue
Block a user