1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-26 12:22:50 +01:00

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

View File

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