Skip to content

Truly independent web browser

LibWebCommon: Match site-compatibility rules by site

Zaggy1024f0b9ff025bb0
diff --git a/Libraries/LibWebCommon/Loader/SiteCompatibility.cpp b/Libraries/LibWebCommon/Loader/SiteCompatibility.cpp
index fbaf62af68c..4830c2e598e 100644
--- a/Libraries/LibWebCommon/Loader/SiteCompatibility.cpp
+++ b/Libraries/LibWebCommon/Loader/SiteCompatibility.cpp
@@ -6,26 +6,43 @@
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
-#include <AK/Mutex.h>
-#include <AK/NeverDestroyed.h>
#include <AK/StringBuilder.h>
+#include <LibURL/Parser.h>
#include <LibWebCommon/Loader/SiteCompatibility.h>
namespace Web {
-static ErrorOr<Vector<String>> parse_patterns(JsonObject const& object)
+// Only a site's own serialization is accepted, such as "https://example.com", so a rule can't name a subdomain, port or
+// path that matching would ignore.
+static ErrorOr<URL::Site> parse_site(StringView serialized_site)
{
- auto patterns = object.get_array("matches"sv);
- if (!patterns.has_value() || patterns->is_empty())
- return Error::from_string_literal("Site-compatibility rule must contain a non-empty 'matches' array");
+ auto url = URL::Parser::basic_parse(serialized_site);
+ if (!url.has_value())
+ return Error::from_string_literal("Site-compatibility rule sites must be URLs");
+
+ auto origin = url->origin();
+ if (origin.is_opaque())
+ return Error::from_string_literal("Site-compatibility rule sites must not be opaque");
+
+ auto site = URL::Site::obtain(origin);
+ if (site.serialize() != serialized_site)
+ return Error::from_string_literal("Site-compatibility rule sites must be serialized sites, such as https://example.com");
+ return site;
+}
+
+static ErrorOr<Vector<String>> parse_sites(JsonObject const& object)
+{
+ auto sites = object.get_array("sites"sv);
+ if (!sites.has_value() || sites->is_empty())
+ return Error::from_string_literal("Site-compatibility rule must contain a non-empty 'sites' array");
Vector<String> result;
- TRY(result.try_ensure_capacity(patterns->size()));
- for (size_t i = 0; i < patterns->size(); ++i) {
- auto const& pattern = patterns->at(i);
- if (!pattern.is_string() || pattern.as_string().is_empty())
- return Error::from_string_literal("Site-compatibility rule patterns must be non-empty strings");
- TRY(result.try_append(pattern.as_string()));
+ TRY(result.try_ensure_capacity(sites->size()));
+ for (size_t i = 0; i < sites->size(); ++i) {
+ auto const& site = sites->at(i);
+ if (!site.is_string())
+ return Error::from_string_literal("Site-compatibility rule sites must be strings");
+ TRY(result.try_append(site.as_string()));
}
return result;
}
@@ -90,27 +107,21 @@ ErrorOr<SiteCompatibilityRule> SiteCompatibilityRule::from_json(JsonValue const&
if (transformations.is_empty() && exposed_interfaces.is_empty())
return Error::from_string_literal("Site-compatibility rule must contain a 'user_agent' or an 'expose_experimental_interfaces' array");
- return create(TRY(parse_patterns(object)), move(transformations), move(exposed_interfaces));
+ return create(TRY(parse_sites(object)), move(transformations), move(exposed_interfaces));
}
-ErrorOr<SiteCompatibilityRule> SiteCompatibilityRule::create(Vector<String> patterns, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces)
+ErrorOr<SiteCompatibilityRule> SiteCompatibilityRule::create(Vector<String> serialized_sites, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces)
{
- Vector<URL::RustIntegration::URLPattern> compiled_patterns;
- TRY(compiled_patterns.try_ensure_capacity(patterns.size()));
-
- for (auto const& pattern : patterns) {
- auto compiled_pattern = URL::RustIntegration::URLPattern::create(pattern);
- if (compiled_pattern.is_error())
- return Error::from_string_literal("Site-compatibility rule contains an invalid URL pattern");
- TRY(compiled_patterns.try_append(compiled_pattern.release_value()));
- }
+ Vector<URL::Site> sites;
+ TRY(sites.try_ensure_capacity(serialized_sites.size()));
+ for (auto const& serialized_site : serialized_sites)
+ TRY(sites.try_append(TRY(parse_site(serialized_site))));
- return SiteCompatibilityRule { move(patterns), move(compiled_patterns), move(transformations), move(exposed_interfaces) };
+ return SiteCompatibilityRule { move(sites), move(transformations), move(exposed_interfaces) };
}
-SiteCompatibilityRule::SiteCompatibilityRule(Vector<String> patterns, Vector<URL::RustIntegration::URLPattern> compiled_patterns, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces)
- : m_patterns(move(patterns))
- , m_compiled_patterns(move(compiled_patterns))
+SiteCompatibilityRule::SiteCompatibilityRule(Vector<URL::Site> sites, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces)
+ : m_sites(move(sites))
, m_user_agent_transformations(move(transformations))
, m_exposed_interfaces(move(exposed_interfaces))
{
@@ -121,21 +132,9 @@ bool SiteCompatibilityRule::exposes_experimental_interface(StringView name) cons
return m_exposed_interfaces.contains_slow(name);
}
-bool SiteCompatibilityRule::matches(URL::URL const& url) const
+bool SiteCompatibilityRule::matches(URL::Site const& site) const
{
- auto serialized_url = url.serialize();
-
- // NB: Agents on different threads share these rules, and a compiled pattern keeps non-atomic state: each regex has
- // a reference count and the scratch space of its matcher. A match is short, and a fetch makes few of them.
- static NeverDestroyed<Mutex> s_match_mutex;
- MutexLocker locker(*s_match_mutex);
-
- for (auto const& pattern : m_compiled_patterns) {
- auto result = pattern.match(serialized_url, {});
- if (!result.is_error() && result.value().has_value())
- return true;
- }
- return false;
+ return m_sites.contains_slow(site);
}
static String remove_ladybird_product(StringView user_agent)
@@ -168,9 +167,11 @@ String SiteCompatibilityRule::apply_user_agent_transformations(StringView user_a
String SiteCompatibilityData::user_agent_for_url(URL::URL const& url, StringView default_user_agent) const
{
+ auto site = URL::Site::obtain(url.origin());
+
auto user_agent = MUST(String::from_utf8(default_user_agent));
for (auto const& rule : m_rules) {
- if (rule.matches(url))
+ if (rule.matches(site))
user_agent = rule.apply_user_agent_transformations(user_agent);
}
return user_agent;
@@ -188,8 +189,10 @@ String SiteCompatibilityData::user_agent_for_websocket_url(URL::URL const& url,
bool SiteCompatibilityData::exposes_experimental_interface(URL::URL const& url, StringView name) const
{
+ auto site = URL::Site::obtain(url.origin());
+
for (auto const& rule : m_rules) {
- if (rule.exposes_experimental_interface(name) && rule.matches(url))
+ if (rule.exposes_experimental_interface(name) && rule.matches(site))
return true;
}
return false;
diff --git a/Libraries/LibWebCommon/Loader/SiteCompatibility.h b/Libraries/LibWebCommon/Loader/SiteCompatibility.h
index af7059cb017..6f4cee2a156 100644
--- a/Libraries/LibWebCommon/Loader/SiteCompatibility.h
+++ b/Libraries/LibWebCommon/Loader/SiteCompatibility.h
@@ -10,7 +10,7 @@
#include <AK/JsonValue.h>
#include <AK/String.h>
#include <AK/Vector.h>
-#include <LibURL/RustIntegration.h>
+#include <LibURL/Site.h>
#include <LibURL/URL.h>
#include <LibWebCommon/Export.h>
@@ -23,21 +23,20 @@ enum class UserAgentTransformation : u8 {
class WEBCOMMON_API SiteCompatibilityRule {
public:
static ErrorOr<SiteCompatibilityRule> from_json(JsonValue const&);
- static ErrorOr<SiteCompatibilityRule> create(Vector<String> patterns, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces = {});
+ static ErrorOr<SiteCompatibilityRule> create(Vector<String> sites, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces = {});
- Vector<String> const& patterns() const { return m_patterns; }
+ Vector<URL::Site> const& sites() const { return m_sites; }
Vector<UserAgentTransformation> const& user_agent_transformations() const { return m_user_agent_transformations; }
Vector<String> const& exposed_interfaces() const { return m_exposed_interfaces; }
- bool matches(URL::URL const&) const;
+ bool matches(URL::Site const&) const;
String apply_user_agent_transformations(StringView user_agent) const;
bool exposes_experimental_interface(StringView name) const;
private:
- SiteCompatibilityRule(Vector<String> patterns, Vector<URL::RustIntegration::URLPattern> compiled_patterns, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces);
+ SiteCompatibilityRule(Vector<URL::Site> sites, Vector<UserAgentTransformation> transformations, Vector<String> exposed_interfaces);
- Vector<String> m_patterns;
- Vector<URL::RustIntegration::URLPattern> m_compiled_patterns;
+ Vector<URL::Site> m_sites;
Vector<UserAgentTransformation> m_user_agent_transformations;
Vector<String> m_exposed_interfaces;
};
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 858fa19e846..d0ea4402dee 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -3,6 +3,9 @@ Layout/input/pdf-viewer.pdf
Text/input/PDF/jbig2-image.html
[LoadFromHttpServer]
+; Site-compatibility rules match the site of the page, and a file: page has none.
+Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html
+Text/input/Fetch/site-compatibility-user-agent-redirects.html
Text/input/HTML/unload-beacon-outlives-its-document.html
Text/input/HTML/reused-window-unload-beacon.html
Text/input/HTML/reused-window-media-document-loads.html
diff --git a/Tests/LibWeb/Text/expected/Fetch/site-compatibility-user-agent-redirects.txt b/Tests/LibWeb/Text/expected/Fetch/site-compatibility-user-agent-redirects.txt
index 79206881a64..79ad641d86f 100644
--- a/Tests/LibWeb/Text/expected/Fetch/site-compatibility-user-agent-redirects.txt
+++ b/Tests/LibWeb/Text/expected/Fetch/site-compatibility-user-agent-redirects.txt
@@ -1,3 +1,3 @@
-non-matching to matching: PASS
-matching to non-matching: PASS
+non-matching to matching: Ladybird/ shown, then hidden
+matching to non-matching: Ladybird/ hidden, then shown
explicit User-Agent preserved: PASS
diff --git a/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html b/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html
index 7c380a088cc..31b084b5bd9 100644
--- a/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html
+++ b/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-change-during-fetch.html
@@ -15,7 +15,7 @@
try {
const responsePromise = fetch(url);
internals.setSiteCompatibilityData(JSON.stringify([{
- matches: [url],
+ sites: [`${location.protocol}//${location.hostname}`],
user_agent: ["hide_Ladybird"],
}]));
diff --git a/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-redirects.html b/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-redirects.html
index 48995797403..c9bee76a144 100644
--- a/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-redirects.html
+++ b/Tests/LibWeb/Text/input/Fetch/site-compatibility-user-agent-redirects.html
@@ -1,47 +1,56 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
+ // A top-level navigation takes the User-Agent of the site each of its requests is for, across redirects.
promiseTest(async () => {
const server = httpTestServer();
- async function redirectedUserAgent(name, initialMatches, finalMatches, explicitUserAgent) {
- const initialPath = `/site-compatibility-user-agent-${name}-initial`;
- const finalPath = `/site-compatibility-user-agent-${name}-final`;
- const finalURL = await server.createEcho("GET", finalPath, {
+ async function navigationUserAgents(name, matchInitial, matchFinal) {
+ const initialHost = uniqueLocalhostHostname(`site-compatibility-${name}-initial`);
+ const finalHost = uniqueLocalhostHostname(`site-compatibility-${name}-final`);
+
+ const finalURL = new URL(await server.createEcho("GET", `/site-compatibility-user-agent-${name}-final`, {
status: 200,
- headers: { "Content-Type": "application/json" },
- reflect_headers_in_body: true,
- });
- const initialURL = await server.createEcho("GET", initialPath, {
+ headers: { "Content-Type": "text/html" },
+ body: "<!DOCTYPE html>",
+ }));
+ finalURL.hostname = finalHost;
+ const initialURL = new URL(await server.createEcho("GET", `/site-compatibility-user-agent-${name}-initial`, {
status: 302,
- headers: { Location: finalURL },
- });
+ headers: { Location: finalURL.href },
+ }));
+ initialURL.hostname = initialHost;
- const matches = [];
- if (initialMatches)
- matches.push(initialURL);
- if (finalMatches)
- matches.push(finalURL);
- internals.setSiteCompatibilityData(JSON.stringify([{
- matches,
- user_agent: ["hide_Ladybird"],
- }]));
+ const sites = [];
+ if (matchInitial)
+ sites.push(`http://${initialHost}`);
+ if (matchFinal)
+ sites.push(`http://${finalHost}`);
+ internals.setSiteCompatibilityData(JSON.stringify([{ sites, user_agent: ["hide_Ladybird"] }]));
+
+ const popup = window.open(initialURL.href);
+ await server.waitForRequest(finalURL.href);
+ popup.close();
- const options = explicitUserAgent
- ? { headers: { "User-Agent": explicitUserAgent } }
- : {};
- const response = await fetch(initialURL, options);
- return (await response.json())["User-Agent"][0];
+ const userAgentOf = async url => (await (await fetch(server.recordedRequestHeadersURL(url))).json())["User-Agent"][0];
+ const shown = userAgent => (userAgent.includes("Ladybird/") ? "shown" : "hidden");
+ return `${shown(await userAgentOf(initialURL.href))}, then ${shown(await userAgentOf(finalURL.href))}`;
}
try {
- const matchingTarget = await redirectedUserAgent("matching-target", false, true);
- println(`non-matching to matching: ${matchingTarget.includes("Ladybird/") ? "FAIL" : "PASS"}`);
+ println(`non-matching to matching: Ladybird/ ${await navigationUserAgents("matching-target", false, true)}`);
+ println(`matching to non-matching: Ladybird/ ${await navigationUserAgents("non-matching-target", true, false)}`);
- const nonMatchingTarget = await redirectedUserAgent("non-matching-target", true, false);
- println(`matching to non-matching: ${nonMatchingTarget.includes("Ladybird/") ? "PASS" : "FAIL"}`);
-
- const explicit = await redirectedUserAgent("explicit", true, true, "CustomAgent/42");
+ const explicitURL = await server.createEcho("GET", "/site-compatibility-user-agent-explicit", {
+ status: 200,
+ headers: { "Content-Type": "application/json" },
+ reflect_headers_in_body: true,
+ });
+ internals.setSiteCompatibilityData(JSON.stringify([{
+ sites: [`${location.protocol}//${location.hostname}`],
+ user_agent: ["hide_Ladybird"],
+ }]));
+ const explicit = (await (await fetch(explicitURL, { headers: { "User-Agent": "CustomAgent/42" } })).json())["User-Agent"][0];
println(`explicit User-Agent preserved: ${explicit === "CustomAgent/42" ? "PASS" : "FAIL"}`);
} catch (error) {
println(`FAIL: ${error}`);
diff --git a/Tests/LibWebCommon/TestSiteCompatibility.cpp b/Tests/LibWebCommon/TestSiteCompatibility.cpp
index 818fa606fba..c5ed5e9634f 100644
--- a/Tests/LibWebCommon/TestSiteCompatibility.cpp
+++ b/Tests/LibWebCommon/TestSiteCompatibility.cpp
@@ -19,49 +19,41 @@ static URL::URL url(StringView input)
return URL::Parser::basic_parse(input).release_value();
}
-TEST_CASE(rule_matches_url_patterns)
+static URL::Site site(StringView input)
{
- auto rule = MUST(Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
- {
- "matches": ["https://www.example.com/*"],
- "user_agent": ["hide_Ladybird"]
- }
- )"sv))));
-
- EXPECT(rule.matches(url("https://www.example.com/article"sv)));
- EXPECT(!rule.matches(url("http://www.example.com/article"sv)));
- EXPECT(!rule.matches(url("https://example.com/article"sv)));
- EXPECT(!rule.matches(url("https://www.example.com.evil.test/article"sv)));
+ return URL::Site::obtain(url(input).origin());
}
-TEST_CASE(rule_matches_apex_and_subdomain_patterns)
+TEST_CASE(rule_matches_its_sites)
{
auto rule = MUST(Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
{
- "matches": ["https://example.com/*", "https://*.example.com/*"],
+ "sites": ["https://example.com"],
"user_agent": ["hide_Ladybird"]
}
)"sv))));
- EXPECT(rule.matches(url("https://example.com/article"sv)));
- EXPECT(rule.matches(url("https://www.example.com/article"sv)));
- EXPECT(rule.matches(url("https://edition.news.example.com/article"sv)));
- EXPECT(!rule.matches(url("https://example.com.evil.test/article"sv)));
- EXPECT(!rule.matches(url("https://notexample.com/article"sv)));
+ EXPECT(rule.matches(site("https://example.com"sv)));
+ EXPECT(rule.matches(site("https://www.example.com"sv)));
+ EXPECT(rule.matches(site("https://edition.news.example.com:8443"sv)));
+ EXPECT(!rule.matches(site("http://example.com"sv)));
+ EXPECT(!rule.matches(site("https://example.com.evil.test"sv)));
+ EXPECT(!rule.matches(site("https://notexample.com"sv)));
+ EXPECT(!rule.matches(URL::Site::obtain(URL::Origin::create_opaque())));
}
// The agents of a process share these rules, each matching on its own thread.
TEST_CASE(rule_matches_on_several_threads_at_once)
{
- IGNORE_USE_IN_ESCAPING_LAMBDA auto rule = MUST(Web::SiteCompatibilityRule::create({ "https://*.example.com/*"_string }, {}));
- IGNORE_USE_IN_ESCAPING_LAMBDA auto matching_url = url("https://www.example.com/page"sv);
+ IGNORE_USE_IN_ESCAPING_LAMBDA auto rule = MUST(Web::SiteCompatibilityRule::create({ "https://example.com"_string }, {}));
+ IGNORE_USE_IN_ESCAPING_LAMBDA auto matching_site = site("https://www.example.com"sv);
IGNORE_USE_IN_ESCAPING_LAMBDA Atomic<size_t> wrong_answers { 0 };
Vector<NonnullRefPtr<Threading::Thread>> threads;
for (size_t i = 0; i < 4; ++i) {
threads.append(Threading::Thread::construct("Matcher"sv, [&] -> intptr_t {
for (size_t round = 0; round < 20'000; ++round) {
- if (!rule.matches(matching_url))
+ if (!rule.matches(matching_site))
wrong_answers.fetch_add(1);
}
return 0;
@@ -78,7 +70,7 @@ TEST_CASE(rule_matches_on_several_threads_at_once)
TEST_CASE(rule_transforms_user_agent)
{
auto rule = MUST(Web::SiteCompatibilityRule::create(
- { "https://www.example.com/*"_string },
+ { "https://example.com"_string },
{ Web::UserAgentTransformation::HideLadybird }));
EXPECT_EQ(rule.apply_user_agent_transformations(default_user_agent), "Mozilla/5.0 Chrome/146.0.0.0 Safari/537.36"_string);
@@ -88,7 +80,7 @@ TEST_CASE(data_only_transforms_matching_urls)
{
Web::SiteCompatibilityData data;
data.add_rule(MUST(Web::SiteCompatibilityRule::create(
- { "https://www.example.com/*"_string },
+ { "https://example.com"_string },
{ Web::UserAgentTransformation::HideLadybird })));
EXPECT_EQ(data.user_agent_for_url(url("https://www.example.com/"sv), default_user_agent), "Mozilla/5.0 Chrome/146.0.0.0 Safari/537.36"_string);
@@ -99,19 +91,17 @@ TEST_CASE(data_maps_websocket_urls_to_http_for_matching)
{
Web::SiteCompatibilityData data;
data.add_rule(MUST(Web::SiteCompatibilityRule::create(
- { "http://www.example.com/*"_string, "https://secure.example.com/*"_string },
+ { "https://example.com"_string },
{ Web::UserAgentTransformation::HideLadybird })));
- EXPECT_EQ(data.user_agent_for_websocket_url(url("ws://www.example.com/socket"sv), default_user_agent), "Mozilla/5.0 Chrome/146.0.0.0 Safari/537.36"_string);
- EXPECT_EQ(data.user_agent_for_websocket_url(url("wss://secure.example.com/socket"sv), default_user_agent), "Mozilla/5.0 Chrome/146.0.0.0 Safari/537.36"_string);
- EXPECT_EQ(data.user_agent_for_websocket_url(url("ws://secure.example.com/socket"sv), default_user_agent), default_user_agent);
- EXPECT_EQ(data.user_agent_for_websocket_url(url("wss://www.example.com/socket"sv), default_user_agent), default_user_agent);
+ EXPECT_EQ(data.user_agent_for_websocket_url(url("wss://www.example.com/socket"sv), default_user_agent), "Mozilla/5.0 Chrome/146.0.0.0 Safari/537.36"_string);
+ EXPECT_EQ(data.user_agent_for_websocket_url(url("ws://www.example.com/socket"sv), default_user_agent), default_user_agent);
}
TEST_CASE(hide_ladybird_only_removes_ladybird_products)
{
auto rule = MUST(Web::SiteCompatibilityRule::create(
- { "https://www.example.com/*"_string },
+ { "https://example.com"_string },
{ Web::UserAgentTransformation::HideLadybird }));
EXPECT_EQ(rule.apply_user_agent_transformations("Ladybird/1.0"sv), String {});
@@ -125,7 +115,7 @@ TEST_CASE(data_parses_rule_array)
{
auto data = MUST(Web::SiteCompatibilityData::from_json(MUST(JsonValue::from_string(R"(
[{
- "matches": ["https://www.example.com/*"],
+ "sites": ["https://example.com"],
"user_agent": ["hide_Ladybird"]
}]
)"sv))));
@@ -136,18 +126,24 @@ TEST_CASE(data_parses_rule_array)
TEST_CASE(invalid_rules_are_rejected)
{
- auto missing_matches = Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
+ auto missing_sites = Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
{ "user_agent": ["hide_Ladybird"] }
)"sv)));
- EXPECT(missing_matches.is_error());
+ EXPECT(missing_sites.is_error());
auto unknown_transformation = Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
- { "matches": ["https://example.com/*"], "user_agent": ["dance"] }
+ { "sites": ["https://example.com"], "user_agent": ["dance"] }
)"sv)));
EXPECT(unknown_transformation.is_error());
- auto invalid_pattern = Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
- { "matches": ["["], "user_agent": ["hide_Ladybird"] }
+ for (auto invalid_site : { "["sv, "example.com"sv, "https://www.example.com"sv, "https://example.com/"sv,
+ "https://example.com/*"sv, "https://example.com:8443"sv, "data:text/plain,"sv }) {
+ auto rule = Web::SiteCompatibilityRule::create({ MUST(String::from_utf8(invalid_site)) }, { Web::UserAgentTransformation::HideLadybird });
+ EXPECT(rule.is_error());
+ }
+
+ auto old_format = Web::SiteCompatibilityRule::from_json(MUST(JsonValue::from_string(R"(
+ { "matches": ["https://example.com/*"], "user_agent": ["hide_Ladybird"] }
)"sv)));
- EXPECT(invalid_pattern.is_error());
+ EXPECT(old_format.is_error());
}
diff --git a/WebCompat/cnn.com.json b/WebCompat/cnn.com.json
index 923c8d145e8..2ac0d3f79fe 100644
--- a/WebCompat/cnn.com.json
+++ b/WebCompat/cnn.com.json
@@ -1,7 +1,6 @@
{
- "matches": [
- "https://cnn.com/*",
- "https://*.cnn.com/*"
+ "sites": [
+ "https://cnn.com"
],
"user_agent": [
"hide_Ladybird"
diff --git a/WebCompat/di.se.json b/WebCompat/di.se.json
index 277d0b4b2e4..05dbfa34f93 100644
--- a/WebCompat/di.se.json
+++ b/WebCompat/di.se.json
@@ -1,7 +1,6 @@
{
- "matches": [
- "https://di.se/*",
- "https://*.di.se/*"
+ "sites": [
+ "https://di.se"
],
"user_agent": [
"hide_Ladybird"
diff --git a/WebCompat/dn.se.json b/WebCompat/dn.se.json
index 41782481742..325bfdc0072 100644
--- a/WebCompat/dn.se.json
+++ b/WebCompat/dn.se.json
@@ -1,7 +1,6 @@
{
- "matches": [
- "https://dn.se/*",
- "https://*.dn.se/*"
+ "sites": [
+ "https://dn.se"
],
"user_agent": [
"hide_Ladybird"
diff --git a/WebCompat/expressen.se.json b/WebCompat/expressen.se.json
index 37d38f0dda6..0f8ed1b5b43 100644
--- a/WebCompat/expressen.se.json
+++ b/WebCompat/expressen.se.json
@@ -1,7 +1,6 @@
{
- "matches": [
- "https://expressen.se/*",
- "https://*.expressen.se/*"
+ "sites": [
+ "https://expressen.se"
],
"user_agent": [
"hide_Ladybird"
diff --git a/WebCompat/nytimes.com.json b/WebCompat/nytimes.com.json
index f9e564b50dd..d88cfdbe60c 100644
--- a/WebCompat/nytimes.com.json
+++ b/WebCompat/nytimes.com.json
@@ -1,6 +1,6 @@
{
- "matches": [
- "https://www.nytimes.com/*"
+ "sites": [
+ "https://nytimes.com"
],
"user_agent": [
"hide_Ladybird"
diff --git a/WebCompat/twitch.tv.json b/WebCompat/twitch.tv.json
index 74dcc96c66d..f019bf2ce99 100644
--- a/WebCompat/twitch.tv.json
+++ b/WebCompat/twitch.tv.json
@@ -1,7 +1,6 @@
{
- "matches": [
- "https://twitch.tv/*",
- "https://*.twitch.tv/*"
+ "sites": [
+ "https://twitch.tv"
],
"user_agent": [
"hide_Ladybird"