mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-01 16:33:06 +01:00
Just extract token from queryprune -- don't create pattern
Related commit:
- 6ac09a2856
Patternless `queryprune` ar enow preserved as being
pattern-less while still attempting to extract a token
from the `queryprune` value. This allows to report the
filter in the logger same as its original form.
This commit is contained in:
parent
8052c0ca14
commit
c2357c5cd6
@ -3114,23 +3114,20 @@ const FilterParser = class {
|
|||||||
|
|
||||||
makeToken() {
|
makeToken() {
|
||||||
if ( this.pattern === '*' ) {
|
if ( this.pattern === '*' ) {
|
||||||
if (
|
if ( this.modifyType !== this.parser.OPTTokenQueryprune ) {
|
||||||
this.modifyType !== this.parser.OPTTokenQueryprune ||
|
|
||||||
this.makePatternFromQuerypruneValue() === false
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
return this.extractTokenFromQuerypruneValue();
|
||||||
}
|
}
|
||||||
if ( this.isRegex ) {
|
if ( this.isRegex ) {
|
||||||
return this.extractTokenFromRegex();
|
return this.extractTokenFromRegex(this.pattern);
|
||||||
}
|
}
|
||||||
this.extractTokenFromPattern();
|
this.extractTokenFromPattern(this.pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: a one-char token is better than a documented bad token.
|
// Note: a one-char token is better than a documented bad token.
|
||||||
extractTokenFromPattern() {
|
extractTokenFromPattern(pattern) {
|
||||||
this.reToken.lastIndex = 0;
|
this.reToken.lastIndex = 0;
|
||||||
const pattern = this.pattern;
|
|
||||||
let bestMatch = null;
|
let bestMatch = null;
|
||||||
let bestBadness = 0x7FFFFFFF;
|
let bestBadness = 0x7FFFFFFF;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -3167,10 +3164,9 @@ const FilterParser = class {
|
|||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1145#issuecomment-657036902
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1145#issuecomment-657036902
|
||||||
// Mind `\b` directives: `/\bads\b/` should result in token being `ads`,
|
// Mind `\b` directives: `/\bads\b/` should result in token being `ads`,
|
||||||
// not `bads`.
|
// not `bads`.
|
||||||
extractTokenFromRegex() {
|
extractTokenFromRegex(pattern) {
|
||||||
|
pattern = vAPI.StaticFilteringParser.regexUtils.toTokenizableStr(pattern);
|
||||||
this.reToken.lastIndex = 0;
|
this.reToken.lastIndex = 0;
|
||||||
const pattern =
|
|
||||||
vAPI.StaticFilteringParser.regexUtils.toTokenizableStr(this.pattern);
|
|
||||||
let bestToken;
|
let bestToken;
|
||||||
let bestBadness = 0x7FFFFFFF;
|
let bestBadness = 0x7FFFFFFF;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -3204,23 +3200,19 @@ const FilterParser = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
makePatternFromQuerypruneValue() {
|
extractTokenFromQuerypruneValue() {
|
||||||
let pattern = this.modifyValue;
|
const pattern = this.modifyValue;
|
||||||
if ( pattern === '*' || pattern.charCodeAt(0) === 0x7E /* '~' */ ) {
|
if ( pattern === '*' || pattern.charCodeAt(0) === 0x7E /* '~' */ ) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
const match = /^\/(.+)\/i?$/.exec(pattern);
|
const match = /^\/(.+)\/i?$/.exec(pattern);
|
||||||
if ( match !== null ) {
|
if ( match !== null ) {
|
||||||
pattern = match[1];
|
return this.extractTokenFromRegex(match[1]);
|
||||||
this.isRegex = true;
|
|
||||||
} else if ( pattern.startsWith('|') ) {
|
|
||||||
pattern = '\\b' + pattern.slice(1);
|
|
||||||
this.isRegex = true;
|
|
||||||
} else {
|
|
||||||
pattern = encodeURIComponent(pattern).toLowerCase() + '=';
|
|
||||||
}
|
}
|
||||||
this.pattern = pattern;
|
if ( pattern.startsWith('|') ) {
|
||||||
return true;
|
return this.extractTokenFromRegex('\\b' + pattern.slice(1));
|
||||||
|
}
|
||||||
|
this.extractTokenFromPattern(encodeURIComponent(pattern).toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
hasNoOptionUnits() {
|
hasNoOptionUnits() {
|
||||||
@ -3246,14 +3238,14 @@ const FilterParser = class {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FilterParser.prototype.DOMAIN_BIT = 0b00000001;
|
FilterParser.prototype.DOMAIN_BIT = 0b00000001;
|
||||||
FilterParser.prototype.DENYALLOW_BIT = 0b00000010;
|
FilterParser.prototype.DENYALLOW_BIT = 0b00000010;
|
||||||
FilterParser.prototype.HEADER_BIT = 0b00000100;
|
FilterParser.prototype.HEADER_BIT = 0b00000100;
|
||||||
FilterParser.prototype.STRICT_PARTY_BIT = 0b00001000;
|
FilterParser.prototype.STRICT_PARTY_BIT = 0b00001000;
|
||||||
|
|
||||||
FilterParser.prototype.CSP_BIT = 0b00010000;
|
FilterParser.prototype.CSP_BIT = 0b00010000;
|
||||||
FilterParser.prototype.QUERYPRUNE_BIT = 0b00100000;
|
FilterParser.prototype.QUERYPRUNE_BIT = 0b00100000;
|
||||||
FilterParser.prototype.REDIRECT_BIT = 0b01000000;
|
FilterParser.prototype.REDIRECT_BIT = 0b01000000;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user