Add extra check to detect function declaration in scriptlets

Related feedback:
- https://www.reddit.com/r/uBlockOrigin/comments/122pqyg/
This commit is contained in:
Raymond Hill 2023-03-26 13:14:00 -04:00
parent 5c9c87e485
commit da672d4dbf
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 10 additions and 6 deletions

View File

@ -171,15 +171,19 @@ const lookupScriptlet = function(rawToken, scriptletMap, dependencyMap) {
if ( Array.isArray(details.dependencies) === false ) { continue; }
dependencies.push(...details.dependencies);
}
scriptletMap.set(
rawToken,
[ 'try {', content, '} catch (e) {', '}' ].join('\n')
);
scriptletMap.set(rawToken, [
'try {',
'// >>>> scriptlet start',
content,
'// <<<< scriptlet end',
'} catch (e) {',
'}',
].join('\n'));
};
// Fill-in scriptlet argument placeholders.
const patchScriptlet = function(content, args) {
if ( content.startsWith('function') ) {
if ( content.startsWith('function') && content.endsWith('}') ) {
content = `(${content})({{args}});`;
}
if ( args.startsWith('{') && args.endsWith('}') ) {
@ -354,7 +358,7 @@ scriptletFilteringEngine.retrieve = function(request, options = {}) {
fullCode.push(code);
}
cacheDetails = {
code: fullCode.join('\n'),
code: fullCode.join('\n\n'),
tokens: Array.from($scriptlets),
exceptions: Array.from($exceptions),
};