diff --git a/browser/brave_shields/ad_block_custom_resources_browsertest.cc b/browser/brave_shields/ad_block_custom_resources_browsertest.cc index ae36928bb455..ec0bcc3c0325 100644 --- a/browser/brave_shields/ad_block_custom_resources_browsertest.cc +++ b/browser/brave_shields/ad_block_custom_resources_browsertest.cc @@ -216,3 +216,32 @@ IN_PROC_BROWSER_TEST_F(AdblockCustomResourcesTest, ExecCustomScriptlet) { EXPECT_EQ("custom-script", EvalJs(web_contents(), "window.test")); } + +IN_PROC_BROWSER_TEST_F(AdblockCustomResourcesTest, NameConflicts) { + constexpr const char kBraveFix[] = "window.test = 'default-script'"; + constexpr const char kBraveFixResource[] = R"json( + [{ + "name": "brave-fix.js", + "kind": { "mime": "application/javascript" }, + "content": "$1" + }] + )json"; + + UpdateAdBlockResources(base::ReplaceStringPlaceholders( + kBraveFixResource, {base::Base64Encode(kBraveFix)}, nullptr)); + + NavigateToURL(GURL("brave://settings/shields/filters")); + + constexpr const char kContent[] = "window.test = 'custom-script'"; + + ASSERT_TRUE(ClickAddCustomScriptlet(web_contents())); + SaveCustomScriptlet("brave-fix", kContent); + + UpdateAdBlockInstanceWithRules("a.com##+js(brave-fix)"); + + GURL tab_url = + embedded_test_server()->GetURL("a.com", "/cosmetic_filtering.html"); + NavigateToURL(tab_url); + + EXPECT_EQ("default-script", EvalJs(web_contents(), "window.test")); +} diff --git a/browser/ui/webui/settings/brave_adblock_handler.cc b/browser/ui/webui/settings/brave_adblock_handler.cc index 95c1ccef1dd7..92d7904c2064 100644 --- a/browser/ui/webui/settings/brave_adblock_handler.cc +++ b/browser/ui/webui/settings/brave_adblock_handler.cc @@ -335,7 +335,6 @@ void BraveAdBlockHandler::UpdateCustomScriptlet(const base::Value::List& args) { void BraveAdBlockHandler::RemoveCustomScriptlet(const base::Value::List& args) { CHECK(base::FeatureList::IsEnabled( brave_shields::features::kCosmeticFilteringCustomScriptlets)); - AllowJavascript(); CHECK(args.size() == 2u && args[0].is_string() && args[1].is_string()); AllowJavascript(); auto error_code = g_brave_browser_process->ad_block_service() diff --git a/components/brave_shields/core/browser/ad_block_custom_resource_provider.cc b/components/brave_shields/core/browser/ad_block_custom_resource_provider.cc index 867b1cc7babe..bb672077cfb7 100644 --- a/components/brave_shields/core/browser/ad_block_custom_resource_provider.cc +++ b/components/brave_shields/core/browser/ad_block_custom_resource_provider.cc @@ -52,7 +52,7 @@ bool IsValidResource(const base::Value& resource) { if (*mime == kAppJs) { // Resource is a scriptlet: - if (!base::StartsWith(*name, "brave-") || !base::EndsWith(*name, ".js")) { + if (!name->starts_with("brave-") || !name->ends_with(".js")) { return false; } } else {