code review #3367 + improve compatibility with Adguard filters

This commit is contained in:
Raymond Hill 2017-12-31 08:44:29 -05:00
parent 17dfec5759
commit 37fde84a45
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 12 additions and 16 deletions

View File

@ -140,23 +140,13 @@
].join(''));
var reEscapeRegex = /[.*+?^${}()|[\]\\]/g,
reNeedScope = /^\s*[+>~]/;
reNeedScope = /^\s*[+>~]/,
reIsDanglingSelector = /(?:[+>~]\s*|\s+)$/;
var lastProceduralSelector = '',
lastProceduralSelectorCompiled,
regexToRawValue = new Map();
var compileCSSSelector = function(s) {
// https://github.com/AdguardTeam/ExtendedCss/issues/31#issuecomment-302391277
// Prepend `:scope ` if needed.
if ( reNeedScope.test(s) ) {
s = ':scope ' + s;
}
if ( isValidCSSSelector(s) ) {
return s;
}
};
var compileText = function(s) {
var regexDetails,
match = reParseRegexLiteral.exec(s);
@ -219,7 +209,7 @@
]);
var compileArgument = new Map([
[ ':has', compileCSSSelector ],
[ ':has', compileConditionalSelector ],
[ ':has-text', compileText ],
[ ':if', compileConditionalSelector ],
[ ':if-not', compileConditionalSelector ],
@ -332,16 +322,22 @@
return;
}
tasks.push([ operator, args ]);
if ( i === n ) { break; }
raw = raw.slice(i);
if ( i === n ) { break; }
}
// No task found: then we have a CSS selector.
// At least one task found: nothing should be left to parse.
if ( tasks.length === 0 ) {
prefix = raw;
tasks = undefined;
}
if ( prefix !== '' && isValidCSSSelector(prefix) === false ) {
} else if ( raw.length !== 0 ) {
return;
}
// https://github.com/NanoAdblocker/NanoCore/issues/1#issuecomment-354394894
if ( prefix !== '' ) {
if ( reIsDanglingSelector.test(prefix) ) { prefix += '*'; }
if ( isValidCSSSelector(prefix) === false ) { return; }
}
return { selector: prefix, tasks: tasks };
};