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;
|
realBad = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( this.interactive ) {
|
|
||||||
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_REPLACE);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1504,8 +1505,8 @@ export class AstFilterParser {
|
||||||
realBad = true;
|
realBad = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const path = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
|
const value = this.getNetOptionValue(NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM);
|
||||||
if ( path.charCodeAt(0) !== 0x2F /* / */ ) {
|
if ( parseReplaceValue(value) === undefined ) {
|
||||||
this.astError = AST_ERROR_OPTION_BADVALUE;
|
this.astError = AST_ERROR_OPTION_BADVALUE;
|
||||||
realBad = true;
|
realBad = true;
|
||||||
}
|
}
|
||||||
|
@ -3008,6 +3009,7 @@ export function parseReplaceValue(s) {
|
||||||
if ( parser.transform ) {
|
if ( parser.transform ) {
|
||||||
pattern = parser.normalizeArg(pattern);
|
pattern = parser.normalizeArg(pattern);
|
||||||
}
|
}
|
||||||
|
if ( pattern === '' ) { return; }
|
||||||
pattern = pattern
|
pattern = pattern
|
||||||
.replace(reEscapedDollarSign, '$1$$$')
|
.replace(reEscapedDollarSign, '$1$$$')
|
||||||
.replace(reEscapedComma, '$1,');
|
.replace(reEscapedComma, '$1,');
|
||||||
|
|
|
@ -5275,9 +5275,21 @@ FilterContainer.prototype.transformRequest = function(fctxt) {
|
||||||
if ( directives === undefined ) { return; }
|
if ( directives === undefined ) { return; }
|
||||||
const directive = directives[directives.length-1];
|
const directive = directives[directives.length-1];
|
||||||
if ( (directive.bits & ALLOW_REALM) !== 0 ) { return directives; }
|
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);
|
const redirectURL = new URL(fctxt.url);
|
||||||
if ( directive.value === redirectURL.pathname ) { return; }
|
const before = redirectURL.pathname + redirectURL.search;
|
||||||
redirectURL.pathname = directive.value;
|
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;
|
fctxt.redirectURL = redirectURL.href;
|
||||||
return directives;
|
return directives;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue