1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 15:33:38 +01:00

Support matching against list of IP addresses

Related commit:
6acf97bf51
This commit is contained in:
Raymond Hill 2024-09-20 07:20:55 -04:00
parent 55ab6d6875
commit 4f181b0bc5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 18 additions and 14 deletions

View File

@ -314,7 +314,7 @@ vAPI.Net = class extends vAPI.Net {
const { addresses } = record;
if ( Array.isArray(addresses) === false ) { return; }
if ( addresses.length === 0 ) { return; }
return addresses[0];
return addresses.join('\n');
}
suspendOneRequest(details) {

View File

@ -174,6 +174,7 @@ export async function benchmarkStaticNetFiltering(options = {}) {
for ( let i = 0; i < requests.length; i++ ) {
const request = requests[i];
fctxt.setURL(request.url);
fctxt.setIPAddress('93.184.215.14\n2606:2800:21f:cb07:6820:80da:af6b:8b2c');
fctxt.setDocOriginFromURL(request.frameUrl);
fctxt.setType(request.cpt);
sfne.redirectURL = undefined;

View File

@ -2993,16 +2993,14 @@ class FilterIPAddress {
if ( ipaddr === '' ) { return false; }
const details = filterRefs[filterData[idata+1]];
switch ( details.$type || this.TYPE_UNKNOWN ) {
case this.TYPE_EQUAL:
return ipaddr === details.pattern;
case this.TYPE_LAN:
return this.isLAN(ipaddr);
case this.TYPE_LOOPBACK:
return this.isLoopback(ipaddr);
case this.TYPE_EQUAL:
case this.TYPE_STARTSWITH:
return ipaddr.startsWith(details.$pattern);
case this.TYPE_RE:
return details.$pattern.test(ipaddr)
return details.$pattern.test(ipaddr);
default:
break;
}
@ -3013,12 +3011,13 @@ class FilterIPAddress {
details.$type = this.TYPE_LOOPBACK;
} else if ( pattern.startsWith('/') && pattern.endsWith('/') ) {
details.$type = this.TYPE_RE;
details.$pattern = new RegExp(pattern.slice(1, -1));
details.$pattern = new RegExp(pattern.slice(1, -1), 'm');
} else if ( pattern.endsWith('*') ) {
details.$type = this.TYPE_STARTSWITH;
details.$pattern = pattern.slice(0, -1);
details.$pattern = new RegExp(`^${restrFromPlainPattern(pattern.slice(0, -1))}`, 'm');
} else {
details.$type = this.TYPE_EQUAL;
details.$pattern = new RegExp(`^${restrFromPlainPattern(pattern)}$`, 'm');
}
return this.match(idata);
}
@ -3049,13 +3048,11 @@ class FilterIPAddress {
if ( ipaddr.startsWith('::ffff:') === false ) { return false; }
return this.reIPv6IPv4lan.test(ipaddr);
}
if ( ipaddr.includes(':') ) {
if ( c0 === 0x36 /* 6 */ ) {
return ipaddr.startsWith('64:ff9b:');
}
if ( c0 === 0x66 /* f */ ) {
return this.reIPv6local.test(ipaddr);
}
if ( c0 === 0x36 /* 6 */ ) {
return ipaddr.startsWith('64:ff9b:');
}
if ( c0 === 0x66 /* f */ ) {
return this.reIPv6local.test(ipaddr);
}
return false;
}
@ -5641,6 +5638,12 @@ StaticNetFilteringEngine.prototype.test = function(details) {
}
}
}
const urlskips = this.matchAndFetchModifiers(fctxt, 'urlskip');
if ( urlskips ) {
for ( const urlskip of urlskips ) {
out.push(`modified: ${urlskip.logData().raw}`);
}
}
return out.join('\n');
}