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

Better handling of separator errors in domain lists

Specifically, do not invalidate valid hostnames when
there are extraneous separators: that sort of error
will be visually highlighted but will not otherwise
prevent a filter from being properly enforced.
This commit is contained in:
Raymond Hill 2020-06-13 17:04:42 -04:00
parent 875a33e381
commit 2523959f20
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 23 additions and 20 deletions

View File

@ -309,9 +309,11 @@
// TODO: Mind negated hostnames, they are currently discarded.
for ( const { hn } of parser.extOptions() ) {
for ( const { hn, not, bad } of parser.extOptions() ) {
if ( bad ) { continue; }
let kind = 0;
if ( exception ) {
if ( not ) { continue; }
kind |= 0b01;
}
if ( compiled.charCodeAt(0) === 0x7B /* '{' */ ) {

View File

@ -305,7 +305,8 @@
// Ignore instances of exception filter with negated hostnames,
// because there is no way to create an exception to an exception.
for ( const { hn, not } of parser.extOptions() ) {
for ( const { hn, not, bad } of parser.extOptions() ) {
if ( bad ) { continue; }
let kind = 0;
if ( exception ) {
if ( not ) { continue; }

View File

@ -483,7 +483,7 @@ const Parser = class {
this.skipUntilNot(
this.patternSpan.i,
lastPatternSlice,
BITHostname
BITHostname | BITAsterisk
) === lastPatternSlice
) {
this.patternRightAnchorSpan.i = lastPatternSlice;
@ -623,15 +623,22 @@ const Parser = class {
analyzeDomainList(from, to, bitSeparator, optionBits) {
if ( from >= to ) { return; }
let beg = from;
// Dangling leading separator?
if ( hasBits(this.slices[beg], bitSeparator) ) {
this.markSlices(beg, beg + 3, BITError);
beg += 3;
}
while ( beg < to ) {
let end = this.skipUntil(beg, to, bitSeparator);
if ( end === -1 ) { end = to; }
if ( end < to && this.slices[end+2] !== 1 ) {
this.markSlices(end, end + 3, BITError);
}
if ( this.analyzeDomain(beg, end, optionBits) === false ) {
this.markSlices(beg, end, BITError);
}
beg = end + 3;
}
// Dangling separator at the end?
// Dangling trailing separator?
if ( hasBits(this.slices[to-3], bitSeparator) ) {
this.markSlices(to - 3, to, BITError);
}
@ -815,18 +822,18 @@ const Parser = class {
}
skipUntil(from, to, bits) {
let i = from + 3;
for (;;) {
if ( i === to || (this.slices[i] & bits) !== 0 ) { break; }
let i = from;
while ( i < to ) {
if ( (this.slices[i] & bits) !== 0 ) { break; }
i += 3;
}
return i;
}
skipUntilNot(from, to, bits) {
let i = from + 3;
for (;;) {
if ( i === to || (this.slices[i] & bits) === 0 ) { break; }
let i = from;
while ( i < to ) {
if ( (this.slices[i] & bits) === 0 ) { break; }
i += 3;
}
return i;
@ -2300,16 +2307,9 @@ const ExtOptionsIterator = class {
if ( hasBits(slices[i], BITComma) ) { break; }
i += 3;
}
if ( i === i0 ) { value.bad = true; }
value.hn = parser.raw.slice(slices[i0+1], slices[i+1]);
if ( i < this.r ) {
if ( interactive && (slices[i+2] !== 1 || (i+3) === this.r) ) {
parser.markSlices(i, i+3, BITError);
}
i += 3;
}
if ( interactive && value.bad ) {
parser.markSlices(this.l, i, BITError);
}
if ( i < this.r ) { i += 3; }
this.l = i;
return this;
}