From f6f7333b5d49132fb4e1a8fc2dd969d785042edf Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 8 Apr 2025 19:01:43 -0400 Subject: [PATCH] Code review for recent commit re path support in target Related commit: https://github.com/gorhill/uBlock/commit/8b696a691a0871da8200d1806300842d988a4326 1) There will always be a `/` at that point in the code path 2) The hostname will already be a match in that code path --- src/js/static-ext-filtering-db.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/js/static-ext-filtering-db.js b/src/js/static-ext-filtering-db.js index bf7ebe711..2e2347491 100644 --- a/src/js/static-ext-filtering-db.js +++ b/src/js/static-ext-filtering-db.js @@ -41,14 +41,11 @@ const extractSubTargets = target => { const isRegex = target.charCodeAt(0) === 0x2F /* / */; if ( isRegex === false ) { const pathPos = target.indexOf('/'); - if ( pathPos !== -1 ) { - return { - isRegex, - hn: target.slice(0, pathPos), - pn: target.slice(pathPos), - }; - } - return { isRegex, hn: target }; + return { + isRegex, + hn: target.slice(0, pathPos), + pn: target.slice(pathPos), + }; } const pathPos = target.indexOf('\\/'); if ( pathPos !== -1 ) { @@ -191,16 +188,12 @@ export class StaticExtFilteringHostnameDB { } #matcherTest(matcher, hn, pn) { - if ( matcher.isRegex ) { - if ( this.#restrTest(matcher.hn, hn) === false ) { return false; } - if ( matcher.pn === undefined ) { return true; } - return this.#restrTest(matcher.pn, pn); + if ( matcher.isRegex === false ) { + return pn.startsWith(matcher.pn); } - if ( hn.endsWith(matcher.hn) === false ) { return false; } - if ( hn.length !== matcher.hn.length ) { - if ( hn.at(hn.length - matcher.hn.length - 1) !== '.' ) { return false; } - } - return pn.startsWith(matcher.pn); + if ( this.#restrTest(matcher.hn, hn) === false ) { return false; } + if ( matcher.pn === undefined ) { return true; } + return this.#restrTest(matcher.pn, pn); } #restrTest(restr, s) {