Ticket #239 (closed defect: duplicate)

Opened 9 months ago

Last modified 7 months ago

False positives when collapsing container of blocked elements

Reported by: esquifit+kabl@… Owned by: t-bone
Priority: minor Component: Karma Blocker
Version: 0.3.2 Severity: Broken
Keywords: collapse Cc:

Description

Test case:

1) Define some rules for blocking 3rd party ads:

[Settings]
threshold=10
cutoff=100

# 3rd party resources
[Group]
score=5
rule=$thirdParty==true

# URLs with a word that starts "ad" or "banner"
[Group]
score=5
rule=$url=~'\b(ad[^d]|banner)'

2) Go to userscripts.org (with javascript enabled), enter something in the "Search" field (on the top right corner) and press 'Enter'.

3) Now:

If Kabl is disabled, the contents of a (dynamically loaded) iframe with search from google.com is shown as expected. Above the search results an input field and as 'Search" button are also displayed.

If Kabl is enabled, no input field and/or button is shown, the iframe is blocked as expected. However, the input field and the 'Search' button are not displayed although they lie outside the iframe.

Diagnostic:

The gKablPolicy.collapse method in kabl-policy.js climbs the DOM tree starting from the blocked element until it finds a container element that does not contain any text whose total length exceeds an arbitrary limit (currently hardcoded to 25 chars). However, it does not make provisions for significant non-textual html like a form. In effect, in the case above the DIV with id="content" contains the search form but it also has a text content consisting of white space with total length = 11, as a result of which it is being collapsed.

Attachments

Change History

Changed 9 months ago by esquifit+kabl@…

One simple (naïve?) way to fix this would be:

--- kabl-policy.js.old	2009-02-14 10:16:58.968750000 +0100
+++ kabl-policy.js	2009-02-14 10:16:25.203125000 +0100
@@ -278,7 +278,8 @@
  // Climb the DOM, from this item, to find a container to collapse.
  var el=null;
  while (item=item.parentNode) {
- 	if (strippedTextContent(item).length>COLLAPSE_TEXT_LENGTH) break;
+ 	if (strippedTextContent(item).length>COLLAPSE_TEXT_LENGTH ||
+           item.getElementsByTagName('FORM').length > 0 ) break;
  
  	el=item;
  }

Changed 9 months ago by t-bone

  • status changed from new to accepted

Yes, the "enhanced" collapsing is quite simplistic right now. The intent is to reclaim the space that is commonly hard-coded to a particular size, and ends up empty when the content disappears. I already plan on making this feature optional in the next release. Thinking about making it more intelligent (like NOT collapsing things like forms) is good as well.

Changed 7 months ago by t-bone

  • status changed from accepted to closed
  • resolution set to duplicate

Ultimately, dupe of #209

Add/Change #239 (False positives when collapsing container of blocked elements)

Author


E-mail address and user name can be saved in the Preferences.


Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.