From 9693d07a6d27fd60d050c014859790ef648301ae Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 5 Jul 2019 12:33:14 -0400 Subject: [PATCH] Code review of https://github.com/gorhill/uBlock/commit/f930da7ad64a --- src/js/scriptlet-filtering.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 19a830cf3..0f2ce6e2e 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -171,22 +171,23 @@ }; })(); - const normalizeRawToken = function(raw) { - let rawEnd = raw.length; - let end = raw.indexOf(','); + const normalizeRawFilter = function(rawFilter) { + let rawToken = rawFilter.slice(4, -1); + let rawEnd = rawToken.length; + let end = rawToken.indexOf(','); if ( end === -1 ) { end = rawEnd; } - let token = raw.slice(0, end).trim(); + let token = rawToken.slice(0, end).trim(); let normalized = token.endsWith('.js') ? token.slice(0, -3) : token; let beg = end + 1; while ( beg < rawEnd ) { - end = raw.indexOf(',', beg); + end = rawToken.indexOf(',', beg); if ( end === -1 ) { end = rawEnd; } - normalized += ', ' + raw.slice(beg, end).trim(); + normalized += ', ' + rawToken.slice(beg, end).trim(); beg = end + 1; } - return normalized; + return `+js(${normalized})`; }; const lookupScriptlet = function(rawToken, reng, toInject) { @@ -270,7 +271,7 @@ writer.select(1001); // Only exception filters are allowed to be global. - const normalized = normalizeRawToken(parsed.suffix); + const normalized = normalizeRawFilter(parsed.suffix); if ( parsed.hostnames.length === 0 ) { if ( parsed.exception ) {