mirror of https://github.com/gorhill/uBlock.git
[mv3] Fix overwriting valid DNR rules with invalid entries
This fixes a flaw which has existed since the first version of
uBO Lite.
Related issue:
- https://github.com/uBlockOrigin/uBOL-issues/issues/11
Related commit:
- a559f5f271
This commit is contained in:
parent
d41b5ebe04
commit
9879b7d03c
|
@ -304,27 +304,27 @@ async function processNetworkFilters(assetDetails, network) {
|
||||||
|
|
||||||
writeFile(
|
writeFile(
|
||||||
`${rulesetDir}/main/${assetDetails.id}.json`,
|
`${rulesetDir}/main/${assetDetails.id}.json`,
|
||||||
`${JSON.stringify(plainGood, replacer)}\n`
|
`${JSON.stringify(plainGood, replacer, 1)}\n`
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( regexes.length !== 0 ) {
|
if ( regexes.length !== 0 ) {
|
||||||
writeFile(
|
writeFile(
|
||||||
`${rulesetDir}/regex/${assetDetails.id}.json`,
|
`${rulesetDir}/regex/${assetDetails.id}.json`,
|
||||||
`${JSON.stringify(regexes, replacer)}\n`
|
`${JSON.stringify(regexes, replacer, 1)}\n`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( removeparamsGood.length !== 0 ) {
|
if ( removeparamsGood.length !== 0 ) {
|
||||||
writeFile(
|
writeFile(
|
||||||
`${rulesetDir}/removeparam/${assetDetails.id}.json`,
|
`${rulesetDir}/removeparam/${assetDetails.id}.json`,
|
||||||
`${JSON.stringify(removeparamsGood, replacer)}\n`
|
`${JSON.stringify(removeparamsGood, replacer, 1)}\n`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( redirects.length !== 0 ) {
|
if ( redirects.length !== 0 ) {
|
||||||
writeFile(
|
writeFile(
|
||||||
`${rulesetDir}/redirect/${assetDetails.id}.json`,
|
`${rulesetDir}/redirect/${assetDetails.id}.json`,
|
||||||
`${JSON.stringify(redirects, replacer)}\n`
|
`${JSON.stringify(redirects, replacer, 1)}\n`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4277,6 +4277,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch id
|
// Patch id
|
||||||
|
const rulesetFinal = [];
|
||||||
{
|
{
|
||||||
let ruleId = 1;
|
let ruleId = 1;
|
||||||
for ( const rule of rulesetMap.values() ) {
|
for ( const rule of rulesetMap.values() ) {
|
||||||
|
@ -4285,16 +4286,15 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
|
||||||
} else {
|
} else {
|
||||||
rule.id = 0;
|
rule.id = 0;
|
||||||
}
|
}
|
||||||
|
rulesetFinal.push(rule);
|
||||||
}
|
}
|
||||||
for ( const invalid of context.invalid ) {
|
for ( const invalid of context.invalid ) {
|
||||||
rulesetMap.set(ruleId++, {
|
rulesetFinal.push({ _error: [ invalid ] });
|
||||||
_error: [ invalid ],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ruleset: Array.from(rulesetMap.values()),
|
ruleset: rulesetFinal,
|
||||||
filterCount: context.filterCount,
|
filterCount: context.filterCount,
|
||||||
acceptedFilterCount: context.acceptedFilterCount,
|
acceptedFilterCount: context.acceptedFilterCount,
|
||||||
rejectedFilterCount: context.rejectedFilterCount,
|
rejectedFilterCount: context.rejectedFilterCount,
|
||||||
|
|
Loading…
Reference in New Issue