Skip to content

Commit

Permalink
[mv3] Do not merge rules with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 6, 2022
1 parent 77e1af7 commit 6574ede
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions platform/mv3/extension/js/ruleset-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,22 @@ async function updateRegexRules() {
// Collate results
const results = await Promise.all(toCheck);
const newRules = [];
const rejectedRegexRules = [];
for ( let i = 0; i < allRules.length; i++ ) {
const rule = allRules[i];
const result = results[i];
if ( result instanceof Object && result.isSupported ) {
newRules.push(rule);
} else {
//console.info(`${result.reason}: ${rule.condition.regexFilter}`);
rejectedRegexRules.push(rule);
}
}
console.info(
`Rejected regex filters: ${allRules.length-newRules.length} out of ${allRules.length}`
);
if ( rejectedRegexRules.length !== 0 ) {
console.info(
'Rejected regexes:',
rejectedRegexRules.map(rule => rule.condition.regexFilter)
);
}

// Add validated regex rules to dynamic ruleset without affecting rules
// outside regex rules realm.
Expand Down
4 changes: 4 additions & 0 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -4175,6 +4175,9 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
}

// Merge rules where possible by merging arrays of a specific property.
//
// /~https://github.com/uBlockOrigin/uBOL-issues/issues/10#issuecomment-1304822579
// Do not merge rules which have errors.
const mergeRules = (rulesetMap, mergeTarget) => {
const mergeMap = new Map();
const sorter = (_, v) => {
Expand Down Expand Up @@ -4216,6 +4219,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
}
};
for ( const [ id, rule ] of rulesetMap ) {
if ( rule._error !== undefined ) { continue; }
const hash = ruleHasher(rule, mergeTarget);
if ( mergeMap.has(hash) === false ) {
mergeMap.set(hash, []);
Expand Down

0 comments on commit 6574ede

Please sign in to comment.