Skip to content

Commit

Permalink
fix: custom styles being ignored for pure has filters (#4506)
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto authored Dec 9, 2024
1 parent 321bc4e commit ad32b49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/adblocker/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ export default class FilterEngine extends EventEmitter<EngineEventHandlers> {
let { stylesheet } = stylesheets;

for (const safeHasFilter of pureHasFilters) {
stylesheet += `\n\n${createStylesheet([safeHasFilter.getSelector()], hidingStyle)}`;
stylesheet += `\n\n${createStylesheet([safeHasFilter.getSelector()], safeHasFilter.hasCustomStyle() ? safeHasFilter.getStyle() : hidingStyle)}`;
}

// Emit events
Expand Down
29 changes: 29 additions & 0 deletions packages/adblocker/test/engine/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,35 @@ foo.com###selector
`#test { display: none !important; }\n\naside:has(a.ad-remove) { display: none !important; }`,
);
});

it('respects custom styles', function () {
expect(
Engine.parse(`foo.com##body:has(a):style(visibility: hidden !important;)`, {
loadExtendedSelectors: false,
}).getCosmeticsFilters({
domain: 'foo.com',
hostname: 'foo.com',
url: 'https://foo.com',
getExtendedRules: false,
injectPureHasSafely: true,
}).styles,
).to.be.eql(`\n\nbody:has(a) { visibility: hidden !important; }`);

expect(
Engine.parse(
`
foo.com##body:has(a):style(visibility: hidden !important;)
foo.com#@#body:has(a):style(visibility: hidden !important;)
`,
).getCosmeticsFilters({
domain: 'foo.com',
hostname: 'foo.com',
url: 'https://foo.com',
getExtendedRules: false,
injectPureHasSafely: true,
}).styles,
).to.be.eql('');
});
});

context('with :styles psuedo-class', function () {
Expand Down

0 comments on commit ad32b49

Please sign in to comment.