<base> tags fixed. (#22249)

This commit is contained in:
Pavel Beloborodov
2024-02-22 10:48:49 -08:00
committed by GitHub
parent c2e055a7ad
commit dfd518c67c
4 changed files with 10 additions and 6 deletions
@@ -891,9 +891,10 @@ IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, Csp) {
NavigateToPageSynchronously(page, WindowOpenDisposition::CURRENT_TAB);
constexpr const char kCheckBaseTag[] = R"js(
document.head.getElementsByTagName('base')[0].outerHTML
document.head.getElementsByTagName('base')[0].outerHTML +
document.head.getElementsByTagName('base')[1].outerHTML
)js";
EXPECT_EQ(R"(<base href="https://a.test/">)",
EXPECT_EQ(R"(<base href="https://a.test/"><base target="_blank">)",
content::EvalJs(ActiveWebContents(), kCheckBaseTag,
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
ISOLATED_WORLD_ID_BRAVE_INTERNAL));
@@ -306,11 +306,13 @@ pub fn extract_dom(
}
if let Some(head) = dom::document_head(&dom) {
let mut base_content = String::default();
let base_nodes = dom::find_nodes_with_tag(&head, &["base"]);
if let Some(base) = base_nodes.get(0) {
// We take the first one, because it is the only one that is effective.
content = base.to_string() + &content;
for base in base_nodes {
base_content += &base.to_string();
}
content = base_content + &content;
}
if let Some(ref charset) = meta.charset {
+1 -1
View File
@@ -7,7 +7,7 @@
<meta http-equiv="Content-Security-Policy" content="img-src 'none';" />
<title>Encrypt the Web with the HTTPS Everywhere Firefox Extension | Electronic Frontier Foundation</title>
<base href="https://a.test/">
<base href="https://should_be_ignored.com/">
<base target="_blank">
</head>
<body>
<div id="main-content">
@@ -5,6 +5,7 @@
<link rel="canonical" href="https://www.eff.org/deeplinks/2010/06/encrypt-web-https-everywhere-firefox-extension" />
<title>Encrypt the Web with the HTTPS Everywhere Firefox Extension | Electronic Frontier Foundation</title>
<base href="https://a.test/">
<base target="_blank">
</head>
<body>
<div id="main-content">