Improve prevent-fetch scriptlet · gorhill/uBlock@e8202af (original) (raw)
`@@ -97,7 +97,7 @@ function safeSelf() {
`
97
97
`},
`
98
98
`initPattern(pattern, options = {}) {
`
99
99
`if ( pattern === '' ) {
`
100
``
`-
return { matchAll: true };
`
``
100
`+
return { matchAll: true, expect: true };
`
101
101
`}
`
102
102
`const expect = (options.canNegate !== true || pattern.startsWith('!') === false);
`
103
103
`if ( expect === false ) {
`
`@@ -2151,7 +2151,7 @@ function noFetchIf(
`
2151
2151
`key = 'url';
`
2152
2152
`value = condition;
`
2153
2153
`}
`
2154
``
`-
needles.push({ key, re: safe.patternToRegex(value) });
`
``
2154
`+
needles.push({ key, pattern: safe.initPattern(value, { canNegate: true }) });
`
2155
2155
`}
`
2156
2156
`const validResponseProps = {
`
2157
2157
`ok: [ false, true ],
`
`@@ -2180,6 +2180,9 @@ function noFetchIf(
`
2180
2180
`const details = args[0] instanceof self.Request
`
2181
2181
` ? args[0]
`
2182
2182
` : Object.assign({ url: args[0] }, args[1]);
`
``
2183
`+
if ( safe.logLevel > 1 ) {
`
``
2184
`` +
safe.uboLog(logPrefix, apply:\n\t${Object.entries(details).map(a => ${a[0]}: ${a[1]}).join('\n\t')});
``
``
2185
`+
}
`
2183
2186
`let proceed = true;
`
2184
2187
`try {
`
2185
2188
`const props = new Map();
`
`@@ -2198,10 +2201,10 @@ function noFetchIf(
`
2198
2201
`return Reflect.apply(target, thisArg, args);
`
2199
2202
`}
`
2200
2203
`proceed = needles.length === 0;
`
2201
``
`-
for ( const { key, re } of needles ) {
`
``
2204
`+
for ( const { key, pattern } of needles ) {
`
2202
2205
`if (
`
2203
``
`-
props.has(key) === false ||
`
2204
``
`-
re.test(props.get(key)) === false
`
``
2206
`+
pattern.expect && props.has(key) === false ||
`
``
2207
`+
safe.testPattern(pattern, props.get(key)) === false
`
2205
2208
`) {
`
2206
2209
`proceed = true;
`
2207
2210
`break;
`