Code review for recent commit re path support in target

Related commit:
8b696a691a

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
This commit is contained in:
Raymond Hill 2025-04-08 19:01:43 -04:00
parent c38101cd34
commit f6f7333b5d
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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) {