Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #8066: Remove invalid selectors (#8068)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuba authored Sep 18, 2023
1 parent 4ee24f3 commit a24129a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,19 @@ window.__firefox__.execute(function($) {
}

return Array.from(CC.hiddenSelectors).filter((selector) => {
return element.matches(selector)
try {
return element.matches(selector)
} catch (error) {
// Remove the culprit from everywhere so it doesn't cause errors
CC.hiddenSelectors.delete(selector)
CC.unhiddenSelectors.add(selector)

for (let queueIndex = 0; queueIndex < CC.runQueues.length; queueIndex += 1) {
CC.runQueues[queueIndex]
CC.runQueues[queueIndex].delete(selector)
}
return false
}
})
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/ClientTests/User Scripts/ScriptExecutionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ final class ScriptExecutionTests: XCTestCase {
@MainActor func testCosmeticFilteringScript() async throws {
// Given
let viewController = MockScriptsViewController()
let invalidSelectors = Set([
"div.invalid-selector:has(span.update-components-actor__description:-abp-contains(/Anzeige|Sponsored|Promoted|Dipromosikan|Propagováno|Promoveret|Gesponsert|Promocionado|促銷內容|Post sponsorisé|프로모션|Post sponsorizzato|广告|プロモーション|Treść promowana|Patrocinado|Promovat|Продвигается|Marknadsfört|Nai-promote|ได้รับการโปรโมท|Öne çıkarılan içerik|Gepromoot|الترويج/))"
])
let initialStandardSelectors = Set([".test-ads-primary-standard div"])
let initialAggressiveSelectors = Set([".test-ads-primary-aggressive div"])
let polledAggressiveIds = ["test-ad-aggressive"]
Expand All @@ -220,7 +223,7 @@ final class ScriptExecutionTests: XCTestCase {
switchToSelectorsPollingThreshold: 1000,
fetchNewClassIdRulesThrottlingMs: 100,
aggressiveSelectors: initialAggressiveSelectors,
standardSelectors: initialStandardSelectors,
standardSelectors: initialStandardSelectors.union(invalidSelectors),
styleSelectors: []
)

Expand Down

0 comments on commit a24129a

Please sign in to comment.