From 2e5edcf27e7d2a212043a7ac1b906217b357b964 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:38:59 +1000 Subject: [PATCH] LibWeb: Use substring matching for content filters --- .../default-config/BrowserContentFilters.txt | 4 ++-- Userland/Libraries/LibWeb/Loader/ContentFilter.cpp | 12 ++---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Base/res/ladybird/default-config/BrowserContentFilters.txt b/Base/res/ladybird/default-config/BrowserContentFilters.txt index 6efc23b0205..3cc87438777 100644 --- a/Base/res/ladybird/default-config/BrowserContentFilters.txt +++ b/Base/res/ladybird/default-config/BrowserContentFilters.txt @@ -406,8 +406,8 @@ glassboxdigital.io go-mpulse.net go2speed.org google-analytics.com -google.com/gen_204\? -google.com/log\? +google.com/gen_204? +google.com/log? googleadservices.com googleoptimize.com googlesyndication.com diff --git a/Userland/Libraries/LibWeb/Loader/ContentFilter.cpp b/Userland/Libraries/LibWeb/Loader/ContentFilter.cpp index d9a8c7cdf38..113a8cbdf55 100644 --- a/Userland/Libraries/LibWeb/Loader/ContentFilter.cpp +++ b/Userland/Libraries/LibWeb/Loader/ContentFilter.cpp @@ -27,7 +27,7 @@ bool ContentFilter::is_filtered(const URL::URL& url) const auto url_string = url.to_byte_string(); for (auto& pattern : m_patterns) { - if (url_string.matches(pattern.text, CaseSensitivity::CaseSensitive)) + if (url_string.find(pattern.text).has_value()) return true; } return false; @@ -38,15 +38,7 @@ ErrorOr ContentFilter::set_patterns(ReadonlySpan patterns) m_patterns.clear_with_capacity(); for (auto const& pattern : patterns) { - StringBuilder builder; - - if (!pattern.starts_with('*')) - TRY(builder.try_append('*')); - TRY(builder.try_append(pattern)); - if (!pattern.ends_with('*')) - TRY(builder.try_append('*')); - - TRY(m_patterns.try_empend(TRY(builder.to_string()))); + TRY(m_patterns.try_empend(pattern)); } return {};