1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

[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:
Raymond Hill 2022-10-18 16:06:27 -04:00
parent d41b5ebe04
commit 9879b7d03c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 8 additions and 8 deletions

View File

@ -304,27 +304,27 @@ async function processNetworkFilters(assetDetails, network) {
writeFile(
`${rulesetDir}/main/${assetDetails.id}.json`,
`${JSON.stringify(plainGood, replacer)}\n`
`${JSON.stringify(plainGood, replacer, 1)}\n`
);
if ( regexes.length !== 0 ) {
writeFile(
`${rulesetDir}/regex/${assetDetails.id}.json`,
`${JSON.stringify(regexes, replacer)}\n`
`${JSON.stringify(regexes, replacer, 1)}\n`
);
}
if ( removeparamsGood.length !== 0 ) {
writeFile(
`${rulesetDir}/removeparam/${assetDetails.id}.json`,
`${JSON.stringify(removeparamsGood, replacer)}\n`
`${JSON.stringify(removeparamsGood, replacer, 1)}\n`
);
}
if ( redirects.length !== 0 ) {
writeFile(
`${rulesetDir}/redirect/${assetDetails.id}.json`,
`${JSON.stringify(redirects, replacer)}\n`
`${JSON.stringify(redirects, replacer, 1)}\n`
);
}

View File

@ -4277,6 +4277,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
}
// Patch id
const rulesetFinal = [];
{
let ruleId = 1;
for ( const rule of rulesetMap.values() ) {
@ -4285,16 +4286,15 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
} else {
rule.id = 0;
}
rulesetFinal.push(rule);
}
for ( const invalid of context.invalid ) {
rulesetMap.set(ruleId++, {
_error: [ invalid ],
});
rulesetFinal.push({ _error: [ invalid ] });
}
}
return {
ruleset: Array.from(rulesetMap.values()),
ruleset: rulesetFinal,
filterCount: context.filterCount,
acceptedFilterCount: context.acceptedFilterCount,
rejectedFilterCount: context.rejectedFilterCount,