mirror of https://github.com/gorhill/uBlock.git
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:
parent
875a33e381
commit
2523959f20
|
@ -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 /* '{' */ ) {
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue