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

Prevent empty selectors from being migrated from legacy cosmetic filters #14763

Closed
antonok-edm opened this issue Mar 16, 2021 · 1 comment · Fixed by brave/brave-core#8270
Closed

Comments

@antonok-edm
Copy link
Collaborator

antonok-edm commented Mar 16, 2021

Test plan

See brave/brave-core#8270

Description

Followup to #9581

As visible in #9581 (comment), migrating the legacy cosmetic filtering implementation to the brave://adblock "Custom filters" box results in some invalid rules that have no CSS selector.

This appears to be caused by the logic for retrieving the selector from window.prompt - a fallback to an empty string is used, even though no rule should be generated if an empty selector is passed, or if the prompt is closed rather than submitted.

This should be fixed by updating the prompt to trim whitespace from the selector, and only adding the rule if it is non-empty. Additionally, any filters migrated from the legacy implementation should be ignored if the selector is blank.

@stephendonner
Copy link

stephendonner commented Mar 19, 2021

Verified PASSED using the testplan from brave/brave-core#8270 with

Brave 1.23.68 Chromium: 90.0.4430.51 (Official Build) (x86_64)
Revision 32e5fa33a31641bded70a90e60121060691e7125-refs/branch-heads/4430@{#927}
OS macOS Version 11.2.3 (Build 20D91)

Verified the following cases:

Migration

Using a previous browser version (1.21.77):

  1. Visit brave://adblock in a new tab
  2. Add some text of your choice to the "Custom filters" box

Screen Shot 2021-03-18 at 4 48 02 PM

I added

SupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidocious

1234567890
foo
facebook.com
https://www.cnn.com
!@#$%^&*()_+
  1. Visit a website of your choice (aol.com, twitch.tv, and sfgate.com)
  2. Right-click on a page element of your choice
  3. Select "Brave > Block element via selector"
  4. Confirm the block
  5. Repeat steps 3-6 a few times to block a variety of items through the legacy system. Block multiple items on the same page at least once. Keep track of what is being blocked. Be sure to close the prompt window, press cancel, or just press OK with an empty rule each at least once.
aol.com (1.21.77) twitch.tv (1.21.77) sfgate.com (1.21.77)
Screen Shot 2021-04-08 at 1 23 23 PM Screen Shot 2021-04-08 at 1 26 59 PM Screen Shot 2021-04-08 at 1 27 48 PM

Then, testing the same profile after the version upgrade:

  1. Visit brave://adblock in a new tab
  2. Verify that any text previously added to the "Custom filters" box is still present
  3. Verify that new lines have been added to the "Custom filters" box, including one corresponding to each item previously blocked using the right click menu, and that no rules were generated that are empty after the ##

Verified there are no empty filter-rule sets in brave://adblock

Screen Shot 2021-04-08 at 1 32 22 PM

  1. Revisit some of the websites and confirm that any previously blocked items are still hidden

Verified that previously blocked elements are still blocked

aol.com (1.23.68) twitch.tv (1.23.68) sfgate.com (1.23.68)
Screen Shot 2021-04-08 at 1 32 33 PM Screen Shot 2021-04-08 at 1 32 41 PM Screen Shot 2021-04-08 at 1 32 28 PM

Adding new filters

Just on 1.23.68:

  1. Visit a website of your choice (cnn.com)
  2. Right-click on a page element of your choice
  3. Select "Brave > Block element via selector"
  4. Confirm the block
  5. Verify that the blocked item is hidden, and remains hidden after a page refresh
  6. Reopen or refresh brave://adblock and verify that a new line has been added corresponding to the newly blocked item
  7. Repeat steps 1-6 at least one more time
  8. Repeat steps 1-6 for each of the following, and ensure that *no* new lines are created in brave://adblock: closing the prompt window, pressing cancel on the prompt window, and pressing OK with an empty rule in the prompt window

Verified there are no empty filter-rule sets in brave://adblock

cnn.com (blocking content / empty selectors) brave://adblock filter set
cnn Screen Shot 2021-04-08 at 1 40 32 PM

Reference images (no blocked items)

aol.com twitch.tv sfgate.com cnn.com
Screen Shot 2021-04-08 at 1 22 13 PM Screen Shot 2021-04-08 at 1 43 40 PM Screen Shot 2021-04-08 at 1 27 23 PM Screen Shot 2021-04-08 at 1 55 54 PM

Verification passed on


Brave | 1.23.59 Chromium: 89.0.4389.114 (Official Build) dev (64-bit)
-- | --
Revision | 1ea76e193b4fadb723bfea2a19a66c93a1bc0ca6-refs/branch-heads/4389@{#1616}
OS | Windows 10 OS Version 2004 (Build 19041.867)

Migration

Installed 1.21.56 and added random text to Custom filter box
image

Visit a website of your choice (aol.com, twitch.tv, and sfgate.com) and block few elements on each site

aol.com (1.21.56) twitch.tv (1.21.56) sfgate.com (1.21.56)
image image image

Upgrade the profile to 1.23.56 and verified the items below:

  1. Visit brave://adblock in a new tab
  2. Verify that any text previously added to the "Custom filters" box is still present
  3. Verify that new lines have been added to the "Custom filters" box, including one corresponding to each item previously blocked using the right click menu, and that no rules were generated that are empty after the ##

Verified there are no empty filter-rule sets in brave://adblock
image

  1. Revisit some of the websites and confirm that any previously blocked items are still hidden

Verified that previously blocked elements are still blocked

aol.com (1.23.59) twitch.tv (1.23.59) sfgate.com (1.23.59)
image image image

Adding new filters

Clean profile 1.23.59. Opened a CNN.COM site and blocked few elements via Brave->Block element via elector and ensured blocked elements on the sites are hidden even after the page reload/refresh
image

Opened brave://adblock and ensured new line has been added corresponding to the newly blocked items for cnn.com
image

ensured that no new lines are created in brave://adblock: closing the prompt window, pressing cancel on the prompt window, and pressing OK with an empty rule in the prompt window
Adblock_1 23 59


Verified passed with

Brave	1.23.68 Chromium: 90.0.4430.51 (Official Build) (64-bit)
Revision	32e5fa33a31641bded70a90e60121060691e7125-refs/branch-heads/4430@{#927}
OS	Linux

Verified test plan from brave/brave-core#8156 (comment)

Migration (Upgrade)

Using a previous browser version (I used 1.22.71):

  1. Visit brave://adblock in a new tab
  2. Add some text of your choice to the "Custom filters" box

I added:

SupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidociousSupercalifragilisticexpialidocious

1234567890
foo
facebook.com
https://www.cnn.com
!@#$%^&*()_+
  1. Visit a website of your choice

aol.com, twitter.com

  1. Right-click on a page element of your choice
  2. Select "Brave > Block element via selector"
  3. Confirm the block
  4. Repeat steps 3-6 a few times to block a variety of items through the legacy system. Block multiple items on the same page at least once. Keep track of what is being blocked. Be sure to close the prompt window, press cancel, or just press OK with an empty rule each at least once.
    • On both pages closed prompt window without saving (used "x")
    • On both pages selected Cancel on prompt window
    • On both pages removed the rule text and selected "OK"

Then, testing the same profile after the upgrade (1.23.68):

  1. Visit brave://adblock in a new tab
  2. Verify that any text previously added to the "Custom filters" box is still present
  3. Verify that new lines have been added to the "Custom filters" box, including one corresponding to each item previously blocked using the right click menu, and that no rules were generated that are empty after the ##. Confirmed there are no empty filter-rule sets in brave://adblock
  4. Revisit some of the websites and confirm that any previously blocked items are still hidden
    • On aol.com, blocked horoscope box on right side, AOL logo in top left, search bar at top of page, and search button at top of page
    • On twitter.com blocked the logo in middle of page

brave://adblock comparison before and after upgrade

1.22.71 1.23.68
adblock before adblock after

Site comparison before and after upgrade

1.22.71 1.23.68 no blocked items for comparison
twitter before twitter after Screen Shot 2021-04-08 at 10 47 58 AM
aol before aol after Screen Shot 2021-04-08 at 10 47 47 AM
Just adding new filters (Clean profile)
  1. Visit a website of your choice

nytimes.com

  1. Right-click on a page element of your choice
  2. Select "Brave > Block element via selector"
  3. Confirm the block
  4. Verify that the blocked item is hidden, and remains hidden after a page refresh
  5. Reopen or refresh brave://adblock and verify that a new line has been added corresponding to the newly blocked item
  6. Repeat steps 1-6 at least one more time
    • Blocked NYT logo/title
    • Blocked "Subscribe" link
  7. Repeat steps 1-6 for each of the following, and ensure that no new lines are created in brave://adblock:
    • closing the prompt window
    • pressing cancel on the prompt window
    • pressing OK with an empty rule in the prompt window
No blocked items Blocked items brave://adblock page
no items blocked items blocked adblock page

@stephendonner stephendonner added QA/In-Progress Indicates that QA is currently in progress for that particular issue QA Pass-macOS and removed QA Pass-macOS QA/In-Progress Indicates that QA is currently in progress for that particular issue labels Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment