1
0
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:
Raymond Hill 2021-01-01 10:23:40 -05:00
parent 8052c0ca14
commit c2357c5cd6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -3114,23 +3114,20 @@ const FilterParser = class {
makeToken() {
if ( this.pattern === '*' ) {
if (
this.modifyType !== this.parser.OPTTokenQueryprune ||
this.makePatternFromQuerypruneValue() === false
) {
if ( this.modifyType !== this.parser.OPTTokenQueryprune ) {
return;
}
return this.extractTokenFromQuerypruneValue();
}
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.
extractTokenFromPattern() {
extractTokenFromPattern(pattern) {
this.reToken.lastIndex = 0;
const pattern = this.pattern;
let bestMatch = null;
let bestBadness = 0x7FFFFFFF;
for (;;) {
@ -3167,10 +3164,9 @@ const FilterParser = class {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1145#issuecomment-657036902
// Mind `\b` directives: `/\bads\b/` should result in token being `ads`,
// not `bads`.
extractTokenFromRegex() {
extractTokenFromRegex(pattern) {
pattern = vAPI.StaticFilteringParser.regexUtils.toTokenizableStr(pattern);
this.reToken.lastIndex = 0;
const pattern =
vAPI.StaticFilteringParser.regexUtils.toTokenizableStr(this.pattern);
let bestToken;
let bestBadness = 0x7FFFFFFF;
for (;;) {
@ -3204,23 +3200,19 @@ const FilterParser = class {
}
}
makePatternFromQuerypruneValue() {
let pattern = this.modifyValue;
extractTokenFromQuerypruneValue() {
const pattern = this.modifyValue;
if ( pattern === '*' || pattern.charCodeAt(0) === 0x7E /* '~' */ ) {
return false;
return;
}
const match = /^\/(.+)\/i?$/.exec(pattern);
if ( match !== null ) {
pattern = match[1];
this.isRegex = true;
} else if ( pattern.startsWith('|') ) {
pattern = '\\b' + pattern.slice(1);
this.isRegex = true;
} else {
pattern = encodeURIComponent(pattern).toLowerCase() + '=';
return this.extractTokenFromRegex(match[1]);
}
this.pattern = pattern;
return true;
if ( pattern.startsWith('|') ) {
return this.extractTokenFromRegex('\\b' + pattern.slice(1));
}
this.extractTokenFromPattern(encodeURIComponent(pattern).toLowerCase());
}
hasNoOptionUnits() {