Have `urltransform=` use the same syntax as `replace=` · gorhill/uBlock@d7c99b4 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit d7c99b4

Browse files
committed
Have urltransform= use the same syntax as replace=
Related issue: uBlockOrigin/uBlock-issues#2924
1 parent 5f78d83 commit d7c99b4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/js/static-filtering-parser.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,10 @@ export class AstFilterParser {
14901490
realBad = true;
14911491
break;
14921492
}
1493-
if ( this.interactive ) {
1494-
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_REPLACE);
1495-
realBad = parseReplaceValue(value) === undefined;
1493+
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_REPLACE);
1494+
if ( parseReplaceValue(value) === undefined ) {
1495+
this.astError = AST_ERROR_OPTION_BADVALUE;
1496+
realBad = true;
14961497
}
14971498
break;
14981499
}
@@ -1504,8 +1505,8 @@ export class AstFilterParser {
15041505
realBad = true;
15051506
break;
15061507
}
1507-
const path = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
1508-
if ( path.charCodeAt(0) !== 0x2F /* / */ ) {
1508+
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
1509+
if ( parseReplaceValue(value) === undefined ) {
15091510
this.astError = AST_ERROR_OPTION_BADVALUE;
15101511
realBad = true;
15111512
}
@@ -3008,6 +3009,7 @@ export function parseReplaceValue(s) {
30083009
if ( parser.transform ) {
30093010
pattern = parser.normalizeArg(pattern);
30103011
}
3012+
if ( pattern === '' ) { return; }
30113013
pattern = pattern
30123014
.replace(reEscapedDollarSign, '$1$$$')
30133015
.replace(reEscapedComma, '$1,');

src/js/static-net-filtering.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,9 +5275,21 @@ FilterContainer.prototype.transformRequest = function(fctxt) {
52755275
if ( directives === undefined ) { return; }
52765276
const directive = directives[directives.length-1];
52775277
if ( (directive.bits & ALLOW_REALM) !== 0 ) { return directives; }
5278+
if ( directive.refs instanceof Object === false ) { return; }
5279+
const { refs } = directive;
5280+
if ( refs.$cache === null ) {
5281+
refs.$cache = sfp.parseReplaceValue(refs.value);
5282+
}
5283+
const cache = refs.$cache;
5284+
if ( cache === undefined ) { return; }
52785285
const redirectURL = new URL(fctxt.url);
5279-
if ( directive.value === redirectURL.pathname ) { return; }
5280-
redirectURL.pathname = directive.value;
5286+
const before = redirectURL.pathname + redirectURL.search;
5287+
if ( cache.re.test(before) !== true ) { return; }
5288+
const after = before.replace(cache.re, cache.replacement);
5289+
if ( after === before ) { return; }
5290+
const searchPos = after.includes('?') && after.indexOf('?') || after.length;
5291+
redirectURL.pathname = after.slice(0, searchPos);
5292+
redirectURL.search = after.slice(searchPos);
52815293
fctxt.redirectURL = redirectURL.href;
52825294
return directives;
52835295
};

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.