LibWeb: Use substring matching for content filters

This commit is contained in:
Gingeh 2024-09-25 17:38:59 +10:00 committed by Andreas Kling
parent 14d62d7f31
commit 2e5edcf27e
Notes: github-actions[bot] 2024-09-28 12:41:41 +00:00
2 changed files with 4 additions and 12 deletions

View file

@ -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

View file

@ -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<void> ContentFilter::set_patterns(ReadonlySpan<String> 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 {};