mirror of https://github.com/gorhill/uBlock.git
Have `urltransform=` use the same syntax as `replace=`
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2924
This commit is contained in:
parent
5f78d83fea
commit
d7c99b46e6
|
@ -1490,9 +1490,10 @@ export class AstFilterParser {
|
|||
realBad = true;
|
||||
break;
|
||||
}
|
||||
if ( this.interactive ) {
|
||||
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_REPLACE);
|
||||
realBad = parseReplaceValue(value) === undefined;
|
||||
if ( parseReplaceValue(value) === undefined ) {
|
||||
this.astError = AST_ERROR_OPTION_BADVALUE;
|
||||
realBad = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1504,8 +1505,8 @@ export class AstFilterParser {
|
|||
realBad = true;
|
||||
break;
|
||||
}
|
||||
const path = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
|
||||
if ( path.charCodeAt(0) !== 0x2F /* / */ ) {
|
||||
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
|
||||
if ( parseReplaceValue(value) === undefined ) {
|
||||
this.astError = AST_ERROR_OPTION_BADVALUE;
|
||||
realBad = true;
|
||||
}
|
||||
|
@ -3008,6 +3009,7 @@ export function parseReplaceValue(s) {
|
|||
if ( parser.transform ) {
|
||||
pattern = parser.normalizeArg(pattern);
|
||||
}
|
||||
if ( pattern === '' ) { return; }
|
||||
pattern = pattern
|
||||
.replace(reEscapedDollarSign, '$1$$$')
|
||||
.replace(reEscapedComma, '$1,');
|
||||
|
|
|
@ -5275,9 +5275,21 @@ FilterContainer.prototype.transformRequest = function(fctxt) {
|
|||
if ( directives === undefined ) { return; }
|
||||
const directive = directives[directives.length-1];
|
||||
if ( (directive.bits & ALLOW_REALM) !== 0 ) { return directives; }
|
||||
if ( directive.refs instanceof Object === false ) { return; }
|
||||
const { refs } = directive;
|
||||
if ( refs.$cache === null ) {
|
||||
refs.$cache = sfp.parseReplaceValue(refs.value);
|
||||
}
|
||||
const cache = refs.$cache;
|
||||
if ( cache === undefined ) { return; }
|
||||
const redirectURL = new URL(fctxt.url);
|
||||
if ( directive.value === redirectURL.pathname ) { return; }
|
||||
redirectURL.pathname = directive.value;
|
||||
const before = redirectURL.pathname + redirectURL.search;
|
||||
if ( cache.re.test(before) !== true ) { return; }
|
||||
const after = before.replace(cache.re, cache.replacement);
|
||||
if ( after === before ) { return; }
|
||||
const searchPos = after.includes('?') && after.indexOf('?') || after.length;
|
||||
redirectURL.pathname = after.slice(0, searchPos);
|
||||
redirectURL.search = after.slice(searchPos);
|
||||
fctxt.redirectURL = redirectURL.href;
|
||||
return directives;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue