This commit is contained in:
Raymond Hill 2018-08-09 11:31:25 -04:00
parent f2ad4144e0
commit 8f1b4b52fd
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 19 additions and 14 deletions

View File

@ -422,16 +422,6 @@
let reHostnameVeryCoarse = /[g-z_-]/; let reHostnameVeryCoarse = /[g-z_-]/;
let reIPv4VeryCoarse = /\.\d+$/; let reIPv4VeryCoarse = /\.\d+$/;
let isIPAddress = function(hostname) {
if ( reHostnameVeryCoarse.test(hostname) ) {
return false;
}
if ( reIPv4VeryCoarse.test(hostname) ) {
return true;
}
return hostname.startsWith('[');
};
let toBroaderHostname = function(hostname) { let toBroaderHostname = function(hostname) {
let pos = hostname.indexOf('.'); let pos = hostname.indexOf('.');
if ( pos !== -1 ) { if ( pos !== -1 ) {
@ -440,15 +430,30 @@
return hostname !== '*' && hostname !== '' ? '*' : ''; return hostname !== '*' && hostname !== '' ? '*' : '';
}; };
let toBroaderIPAddress = function(ipaddress) { let toBroaderIPv4Address = function(ipaddress) {
if ( ipaddress === '*' || ipaddress === '' ) { return ''; }
let pos = ipaddress.lastIndexOf('.');
if ( pos === -1 ) { return '*'; }
return ipaddress.slice(0, pos);
};
let toBroaderIPv6Address = function(ipaddress) {
return ipaddress !== '*' && ipaddress !== '' ? '*' : ''; return ipaddress !== '*' && ipaddress !== '' ? '*' : '';
}; };
return function decomposeHostname(hostname, decomposed) { return function decomposeHostname(hostname, decomposed) {
if ( decomposed.length === 0 || decomposed[0] !== hostname ) { if ( decomposed.length === 0 || decomposed[0] !== hostname ) {
let broaden = isIPAddress(hostname) ? let broaden;
toBroaderIPAddress : if ( reHostnameVeryCoarse.test(hostname) === false ) {
toBroaderHostname; if ( reIPv4VeryCoarse ) {
broaden = toBroaderIPv4Address;
} else if ( hostname.startsWith('[') ) {
broaden = toBroaderIPv6Address;
}
}
if ( broaden === undefined ) {
broaden = toBroaderHostname;
}
decomposed[0] = hostname; decomposed[0] = hostname;
let i = 1; let i = 1;
for (;;) { for (;;) {