Parser: MAC address parser returns original string if grossly invalid. Fixes #895

The MAC parser does not validate the address!
This commit is contained in:
Mottie 2015-05-04 07:42:00 -05:00
parent 79ea44ad07
commit ba9f6ae58e
2 changed files with 28 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*! Parser: network - updated 10/26/2014 (v2.18.0) */
/*! Parser: network - updated 5/4/2015 (v2.21.6) */
!function(a){"use strict";var b,c,d=a.tablesorter;/*! IPv6 Address parser (WIP) */
a.extend(d.regex,{},{ipv4Validate:/((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})/,ipv4Extract:/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/,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}),d.addParser({id:"ipv6Address",is:function(a){return d.regex.ipv6Validate.test(a)},format:function(a,b){var c,e,f,g,h,i=b?"boolean"==typeof b?b:b&&b.config.ipv6HexFormat||!1:!1,j="",k="",l=8;if(a=a.replace(/\s*/g,""),d.regex.ipv4Validate.test(a)){for(g=a.match(d.regex.ipv4Extract),e="",c=1;c<g.length;c++)e+=("00"+parseInt(g[c],10).toString(16)).slice(-2)+(2===c?":":"");a=a.replace(d.regex.ipv4Extract,e)}if(-1==a.indexOf("::"))j=a;else{for(f=a.split("::"),h=0,c=0;c<f.length;c++)h+=f[c].split(":").length;for(j+=f[0]+":",c=0;l-h>c;c++)j+="0000:";j+=f[1]}for(g=j.split(":"),c=0;l>c;c++)g[c]=i?("0000"+g[c]).slice(-4):("00000"+(parseInt(g[c],16)||0)).slice(-5),k+=c!=l-1?g[c]+":":g[c];return i?k:k.replace(/:/g,"")},type:"numeric"}),c=function(a){return/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(a)},b=function(a,b){var c,e=a?a.split("."):"",f="",g=e.length;for(c=0;g>c;c++)f+=("000"+e[c]).slice(-3);return a?d.formatFloat(f,b):a},/*! Parser: ipv4Address (a.k.a. ipAddress) */
d.addParser({id:"ipAddress",is:c,format:b,type:"numeric"}),d.addParser({id:"ipv4Address",is:c,format:b,type:"numeric"}),/*! Parser: MAC address */
d.addParser({id:"MAC",is:function(a){return d.regex.ipv6Validate.test(a)},format:function(b){var c="",d=b.replace(/[:.-]/g,"").match(/\w{2}/g);return a.each(d,function(a,b){c+=("000"+parseInt(b,16)).slice(-3)}),c},type:"numeric"})}(jQuery);
d.addParser({id:"MAC",is:function(a){return d.regex.ipv6Validate.test(a)},format:function(a){var b,c,d="",e=(a||"").replace(/[:.-]/g,"").match(/\w{2}/g);if(e){for(c=e.length,b=0;c>b;b++)d+=("000"+parseInt(e[b],16)).slice(-3);return d}return a},type:"numeric"})}(jQuery);

View File

@ -1,8 +1,8 @@
/*! Parser: network - updated 10/26/2014 (v2.18.0) */
/*! Parser: network - updated 5/4/2015 (v2.21.6) */
/* IPv4, IPv6 and MAC Addresses */
/*global jQuery: false */
;(function($){
"use strict";
'use strict';
var ts = $.tablesorter,
ipv4Format,
@ -10,8 +10,8 @@
/*! IPv6 Address parser (WIP) *//*
* IPv6 Address (ffff:0000:0000:0000:0000:0000:0000:0000)
* needs to support short versions like "::8" or "1:2::7:8"
* and "::00:192.168.10.184" (embedded IPv4 address)
* needs to support short versions like '::8' or '1:2::7:8'
* and '::00:192.168.10.184' (embedded IPv4 address)
* see http://www.intermapper.com/support/tools/IPV6-Validator.aspx
*/
$.extend( ts.regex, {}, {
@ -93,7 +93,7 @@
};
/*! Parser: ipv4Address (a.k.a. ipAddress) */
// duplicate "ipAddress" as "ipv4Address" (to maintain backwards compatility)
// duplicate 'ipAddress' as 'ipv4Address' (to maintain backwards compatility)
ts.addParser({
id: 'ipAddress',
is: ipv4Is,
@ -108,18 +108,27 @@
});
/*! Parser: MAC address */
/* MAC examples: 12:34:56:78:9A:BC, 1234.5678.9ABC, 12-34-56-78-9A-BC, and 123456789ABC
*/
ts.addParser({
id : 'MAC',
is: function(s) {
return ts.regex.ipv6Validate.test(s);
is : function( str ) {
return ts.regex.ipv6Validate.test(str);
},
format: function(s) {
var t = '',
val = s.replace(/[:.-]/g, '').match(/\w{2}/g);
$.each(val, function(i, v){
t += ( '000' + parseInt(v, 16) ).slice(-3);
});
return t;
format : function( str ) {
var indx, len,
mac = '',
val = ( str || '' ).replace( /[:.-]/g, '' ).match( /\w{2}/g );
if ( val ) {
// 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
len = val.length;
for ( indx = 0; indx < len; indx++ ) {
mac += ( '000' + parseInt( val[ indx ], 16 ) ).slice( -3 );
}
return mac;
}
return str;
},
// uses natural sort hex compare
type : 'numeric'