Commit 24d87e2f authored by lpy's avatar lpy Committed by Commit bot

Fix empty href for favicon link element causing page to be fetched twice.

Accroding to HTML spec
https://html.spec.whatwg.org/multipage/semantics.html#the-link-element, if the
href attribute in link element is empty, then the element does not define a link
and should be ignored.

BUG=669351

Review-Url: https://codereview.chromium.org/2575273002
Cr-Commit-Position: refs/heads/master@{#438762}
parent f212359e
......@@ -1145,6 +1145,7 @@ source_set("unit_tests") {
"html/HTMLImageElementTest.cpp",
"html/HTMLInputElementTest.cpp",
"html/HTMLLinkElementSizesAttributeTest.cpp",
"html/HTMLLinkElementTest.cpp",
"html/HTMLMediaElementTest.cpp",
"html/HTMLOutputElementTest.cpp",
"html/HTMLSelectElementTest.cpp",
......
......@@ -324,7 +324,10 @@ const QualifiedName& HTMLLinkElement::subResourceAttributeName() const {
}
KURL HTMLLinkElement::href() const {
return document().completeURL(getAttribute(hrefAttr));
const String& url = getAttribute(hrefAttr);
if (url.isEmpty())
return KURL();
return document().completeURL(url);
}
const AtomicString& HTMLLinkElement::rel() const {
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/html/HTMLLinkElement.h"
#include "core/dom/Document.h"
#include "core/frame/FrameView.h"
#include "core/html/HTMLHeadElement.h"
#include "core/testing/DummyPageHolder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
class HTMLLinkElementTest : public ::testing::Test {
protected:
void SetUp() override;
Document& document() const { return m_dummyPageHolder->document(); }
private:
std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
};
void HTMLLinkElementTest::SetUp() {
m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
}
// This tests that we should ignore empty string value
// in href attribute value of the link element.
TEST_F(HTMLLinkElementTest, EmptyHrefAttribute) {
document().documentElement()->setInnerHTML(
"<head>"
"<link rel=\"icon\" type=\"image/ico\" href=\"\" />"
"</head>");
HTMLLinkElement* linkElement =
toElement<HTMLLinkElement>(document().head()->firstChild());
EXPECT_EQ(KURL(), linkElement->href());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment