Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge: allow config differences #4519

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/adblocker/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ export default class FilterEngine extends EventEmitter<EngineEventHandlers> {
const configKeysMustMatch: ConfigKey[] = (Object.keys(config) as (keyof Config)[]).filter(
function (key): key is ConfigKey {
return (
typeof config[key] === 'boolean' && !compatibleConfigKeys.includes(key as ConfigKey)
typeof config[key] === 'boolean' &&
!compatibleConfigKeys.includes(key as ConfigKey) &&
!Object.hasOwnProperty.call(overrideConfig, key)
);
},
);
Expand Down
22 changes: 22 additions & 0 deletions packages/adblocker/test/engine/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,28 @@ foo.com###selector
});
});

context.only('valides configs', () => {
it('throws with different configs', () => {
const engine1 = FilterEngine.empty({ loadCosmeticFilters: true });
const engine2 = FilterEngine.empty({ loadCosmeticFilters: false });
expect(() => FilterEngine.merge([engine1, engine2])).to.throw(
`config "loadCosmeticFilters" of all merged engines must be the same`,
);
});

it('does not check overridden configs', () => {
const engine1 = FilterEngine.empty({ enableCompression: true });
const engine2 = FilterEngine.empty({ enableCompression: false });
let engine: FilterEngine;
expect(() => {
engine = FilterEngine.merge([engine1, engine2], {
overrideConfig: { enableCompression: false },
});
}).not.to.throw();
expect(engine!.config).to.have.property('enableCompression').that.equal(false);
});
});

context('with resources', () => {
it('throws with different checksums', () => {
const engine1 = FilterEngine.empty();
Expand Down
Loading