<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[280855] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/280855">280855</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2021-08-10 10:51:30 -0700 (Tue, 10 Aug 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Document.baseURI is inaccurate for iframe srcdoc documents
https://bugs.webkit.org/show_bug.cgi?id=228933

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT tests now that more checks are passing.

* web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt:
* web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt:
* web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt:
* web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt:

Source/WebCore:

Document.baseURI is inaccurate for iframe srcdoc documents:
- https://html.spec.whatwg.org/#fallback-base-url

This aligns our behavior with both Chrome and Firefox.

No new tests, rebaselined existing tests.

* dom/Document.cpp:
(WebCore::Document::fallbackBaseURL const):
(WebCore::Document::updateBaseURL):
Extract "fallback base URL" logic out of updateBaseURL() and into its own function so that
it can be called from other places. Add logic to deal with iframe srcdoc documents to
our "fallback base URL" logic, as per:
- https://html.spec.whatwg.org/#fallback-base-url

(WebCore::Document::processBaseElement):
As per https://html.spec.whatwg.org/#set-the-frozen-base-url, we should use the document's fallback base URL
as base URL when parsing the base element's href attribute.

* dom/Document.h:

* html/HTMLBaseElement.cpp:
(WebCore::HTMLBaseElement::href const):
Per https://html.spec.whatwg.org/#dom-base-href, we should use the document's fallback base URL when
parsing the base element's href attribute. Also we should return the attribute value if the URL fails
parsing, not a null URL.

* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::openFunc):
Keep in sync with HTMLBaseElement::href(), as per comment.

Source/WebKitLegacy/mac:

* DOM/DOMHTMLBaseElement.mm:
(-[DOMHTMLBaseElement href]):

LayoutTests:

Update existing layout test to reflect behavior change.

* fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html: Removed.
* http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt: Renamed from LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt.
* http/tests/misc/href-attribute-resolves-with-respect-to-document.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlinfrastructureurlsterminology0documentbaseurlexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_about_blankexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_href_invalidexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_srcdocexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLBaseElementcpp">trunk/Source/WebCore/html/HTMLBaseElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLBaseElementh">trunk/Source/WebCore/html/HTMLBaseElement.h</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp">trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp</a></li>
<li><a href="#trunkSourceWebKitLegacymacChangeLog">trunk/Source/WebKitLegacy/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitLegacymacDOMDOMHTMLBaseElementmm">trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLBaseElement.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestshttptestsmischrefattributeresolveswithrespecttodocumentexpectedtxt">trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt</a></li>
<li><a href="#trunkLayoutTestshttptestsmischrefattributeresolveswithrespecttodocumenthtml">trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document.html</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomHTMLBaseElementhrefattributeresolveswithrespecttodocumentexpectedtxt">trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomHTMLBaseElementhrefattributeresolveswithrespecttodocumenthtml">trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/ChangeLog 2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-08-10  Chris Dumez  <cdumez@apple.com>
+
+        Document.baseURI is inaccurate for iframe srcdoc documents
+        https://bugs.webkit.org/show_bug.cgi?id=228933
+
+        Reviewed by Alex Christensen.
+
+        Update existing layout test to reflect behavior change.
+
+        * fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html: Removed.
+        * http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt: Renamed from LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt.
+        * http/tests/misc/href-attribute-resolves-with-respect-to-document.html: Added.
+
</ins><span class="cx"> 2021-08-10  Arcady Goldmints-Orlov  <agoldmints@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [GLIB] Update crypto test baselines after r280790
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomHTMLBaseElementhrefattributeresolveswithrespecttodocumentexpectedtxt"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt 2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt    2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,14 +0,0 @@
</span><del>-PASS endsWith(document.querySelector('base').href, 'foo/bar/') is true
-PASS endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/') is false
-PASS document.querySelector('base').hasAttribute('href') is true
-PASS endsWith(document.querySelector('base').href, '/null') is true
-PASS document.querySelector('base').hasAttribute('href') is false
-PASS endsWith(document.querySelector('base').href, '/href-attribute-resolves-with-respect-to-document.html') is true
-PASS documentWithoutAView.querySelector('base').href is ""
-PASS documentWithoutAView.querySelector('base').href is "http://webkit.org/"
-PASS iframe.contentDocument.querySelector('base').href is ""
-PASS newWindow.document.querySelector('base').href is ""
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
</del></span></pre></div>
<a id="trunkLayoutTestsfastdomHTMLBaseElementhrefattributeresolveswithrespecttodocumenthtml"></a>
<div class="delfile"><h4>Deleted: trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html 2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html    2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,62 +0,0 @@
</span><del>-<!DOCTYPE html>
-<script src="../../../resources/js-test-pre.js"></script>
-<base href="foo/bar/">
-<body></body>
-<script>
-
-if (window.testRunner) {
-    // FIXME: setCanOpenWindows needs the test to be async or the Apple port crashes.
-    // https://bugs.webkit.org/show_bug.cgi?id=99465
-    window.jsTestIsAsync = true;
-    testRunner.waitUntilDone();
-    testRunner.setCanOpenWindows();
-}
-
-function endsWith(string, substring)
-{
-    var length = string.length - substring.length;
-    return length >= 0 && string.indexOf(substring, length) === length;
-}
-
-var base = document.querySelector('base');
-shouldBeTrue("endsWith(document.querySelector('base').href, 'foo/bar/')");
-shouldBeFalse("endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/')");
-
-base.href = null;
-shouldBeTrue("document.querySelector('base').hasAttribute('href')");
-shouldBeTrue("endsWith(document.querySelector('base').href, '/null')");
-
-base.removeAttribute('href');
-shouldBeFalse("document.querySelector('base').hasAttribute('href')");
-shouldBeTrue("endsWith(document.querySelector('base').href, '/href-attribute-resolves-with-respect-to-document.html')");
-
-// When a document does not have a URL, base cannot be resolved
-
-// Make sure that we don't use the creator document as the base.
-var documentWithoutAView = document.implementation.createHTMLDocument('');
-base = documentWithoutAView.head.appendChild(documentWithoutAView.createElement('base'));
-base.setAttribute('href', 'foo/bar/');
-shouldBeEqualToString("documentWithoutAView.querySelector('base').href", '');
-base.setAttribute('href', 'http://webkit.org/');
-shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'http://webkit.org/');
-
-// Make sure that we use the parent document as the base.
-var iframe = document.body.appendChild(document.createElement('iframe'));
-base = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElement('base'));
-base.setAttribute('href', 'foo/bar/');
-shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", '');
-
-// Make sure that we don't use the opener document as the base.
-var newWindow = window.open('about:blank');
-base = newWindow.document.head.appendChild(newWindow.document.createElement('base'));
-base.setAttribute('href', 'foo/bar/');
-shouldBeEqualToString("newWindow.document.querySelector('base').href", '');
-newWindow.close();
-
-</script>
-<script src="../../../resources/js-test-post.js"></script>
-<script>
-
-finishJSTest();
-
-</script>
</del></span></pre></div>
<a id="trunkLayoutTestshttptestsmischrefattributeresolveswithrespecttodocumentexpectedtxtfromrev280854trunkLayoutTestsfastdomHTMLBaseElementhrefattributeresolveswithrespecttodocumentexpectedtxt"></a>
<div class="copfile"><h4>Copied: trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt (from rev 280854, trunk/LayoutTests/fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document-expected.txt) (0 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt                          (rev 0)
+++ trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt     2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+Test for HTMLBaseElement's href attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS endsWith(document.querySelector('base').href, 'foo/bar/') is true
+PASS endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/') is false
+PASS document.querySelector('base').hasAttribute('href') is true
+PASS endsWith(document.querySelector('base').href, '/null') is true
+PASS document.querySelector('base').hasAttribute('href') is false
+PASS endsWith(document.querySelector('base').href, '/href-attribute-resolves-with-respect-to-document.html') is true
+PASS documentWithoutAView.querySelector('base').href is "foo/bar/"
+PASS documentWithoutAView.querySelector('base').href is "http://webkit.org/"
+PASS iframe.contentDocument.querySelector('base').href is "http://127.0.0.1:8000/misc/foo/bar/"
+PASS newWindow.document.querySelector('base').href is "http://127.0.0.1:8000/misc/foo/bar/"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestshttptestsmischrefattributeresolveswithrespecttodocumenthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document.html (0 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document.html                          (rev 0)
+++ trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document.html     2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+<!DOCTYPE html>
+<script src="/js-test-resources/js-test.js"></script>
+<base href="foo/bar/">
+<body></body>
+<script>
+
+description("Test for HTMLBaseElement's href attribute.");
+jsTestIsAsync = true;
+
+if (window.testRunner)
+    testRunner.setCanOpenWindows();
+
+function endsWith(string, substring)
+{
+    var length = string.length - substring.length;
+    return length >= 0 && string.indexOf(substring, length) === length;
+}
+
+onload = () => {
+    base = document.querySelector('base');
+    shouldBeTrue("endsWith(document.querySelector('base').href, 'foo/bar/')");
+    shouldBeFalse("endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/')");
+
+    base.href = null;
+    shouldBeTrue("document.querySelector('base').hasAttribute('href')");
+    shouldBeTrue("endsWith(document.querySelector('base').href, '/null')");
+
+    base.removeAttribute('href');
+    shouldBeFalse("document.querySelector('base').hasAttribute('href')");
+    shouldBeTrue("endsWith(document.querySelector('base').href, '/href-attribute-resolves-with-respect-to-document.html')");
+
+    // When a document does not have a URL, base cannot be resolved
+
+    // Make sure that we don't use the creator document as the base.
+    documentWithoutAView = document.implementation.createHTMLDocument('');
+    base = documentWithoutAView.head.appendChild(documentWithoutAView.createElement('base'));
+    base.setAttribute('href', 'foo/bar/');
+    shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'foo/bar/');
+    base.setAttribute('href', 'http://webkit.org/');
+    shouldBeEqualToString("documentWithoutAView.querySelector('base').href", 'http://webkit.org/');
+
+    // Make sure that we use the parent document as the base.
+    iframe = document.body.appendChild(document.createElement('iframe'));
+    base = iframe.contentDocument.head.appendChild(iframe.contentDocument.createElement('base'));
+    base.setAttribute('href', 'foo/bar/');
+    shouldBeEqualToString("iframe.contentDocument.querySelector('base').href", 'http://127.0.0.1:8000/misc/foo/bar/');
+
+    // Make sure that we use the opener document as the base.
+    newWindow = window.open('about:blank');
+    base = newWindow.document.head.appendChild(newWindow.document.createElement('base'));
+    base.setAttribute('href', 'foo/bar/');
+    shouldBeEqualToString("newWindow.document.querySelector('base').href", 'http://127.0.0.1:8000/misc/foo/bar/');
+    newWindow.close();
+
+    setTimeout(finishJSTest, 0);
+}
+</script>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2021-08-10  Chris Dumez  <cdumez@apple.com>
+
+        Document.baseURI is inaccurate for iframe srcdoc documents
+        https://bugs.webkit.org/show_bug.cgi?id=228933
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline WPT tests now that more checks are passing.
+
+        * web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt:
+        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt:
+        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt:
+        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt:
+
</ins><span class="cx"> 2021-08-10  Cathie Chen  <cathiechen@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         Import css/css-sizing/aspect-ratio tests from WPT
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlinfrastructureurlsterminology0documentbaseurlexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt  2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt     2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> PASS The document base URL of a document containing one or more base elements with href attributes is the frozen base URL of the first base element in the document that has an href attribute, in tree order.
</span><span class="cx"> PASS The fallback base URL of a document containing no base element is the document's address.
</span><span class="cx"> PASS The fallback base URL of a document whose address is about:blank is the document base URL of the creator document.
</span><del>-FAIL about:blank with a base element. assert_equals: img src should resolve correctly expected "http://localhost:8800/html/infrastructure/urls/terminology-0/sub/foo" but got "http://localhost:8800/html/infrastructure/urls/terminology-0/foo"
</del><ins>+PASS about:blank with a base element.
</ins><span class="cx"> PASS The fallback base URL of an iframe srcdoc document is the document base URL of the document's browsing context's browsing context container's document.
</span><del>-FAIL The base URL of an iframe srcdoc document with a <base> tag should be set by that tag. assert_equals: img src should resolve correctly expected "http://localhost:8800/html/infrastructure/urls/terminology-0/sub/foo" but got "http://localhost:8800/html/infrastructure/urls/terminology-0/foo"
</del><ins>+PASS The base URL of an iframe srcdoc document with a <base> tag should be set by that tag.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_about_blankexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt        2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt   2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-FAIL base element in about:blank document should resolve against its fallback base URI assert_equals: expected "http://localhost:8800/html/semantics/document-metadata/the-base-element/test" but got ""
</del><ins>+PASS base element in about:blank document should resolve against its fallback base URI
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_href_invalidexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt       2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt  2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,3 +1,3 @@
</span><span class="cx"> 
</span><del>-FAIL base element with unparseable href should have .href getter return attr value assert_equals: expected "//test:test" but got ""
</del><ins>+PASS base element with unparseable href should have .href getter return attr value
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestshtmlsemanticsdocumentmetadatathebaseelementbase_srcdocexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt     2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt        2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-FAIL base element in srcdoc document should resolve against its fallback base URI assert_equals: expected "http://localhost:8800/html/semantics/document-metadata/the-base-element/test" but got ""
</del><ins>+PASS base element in srcdoc document should resolve against its fallback base URI
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/ChangeLog      2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2021-08-10  Chris Dumez  <cdumez@apple.com>
+
+        Document.baseURI is inaccurate for iframe srcdoc documents
+        https://bugs.webkit.org/show_bug.cgi?id=228933
+
+        Reviewed by Alex Christensen.
+
+        Document.baseURI is inaccurate for iframe srcdoc documents:
+        - https://html.spec.whatwg.org/#fallback-base-url
+
+        This aligns our behavior with both Chrome and Firefox.
+
+        No new tests, rebaselined existing tests.
+
+        * dom/Document.cpp:
+        (WebCore::Document::fallbackBaseURL const):
+        (WebCore::Document::updateBaseURL):
+        Extract "fallback base URL" logic out of updateBaseURL() and into its own function so that
+        it can be called from other places. Add logic to deal with iframe srcdoc documents to
+        our "fallback base URL" logic, as per:
+        - https://html.spec.whatwg.org/#fallback-base-url
+
+        (WebCore::Document::processBaseElement):
+        As per https://html.spec.whatwg.org/#set-the-frozen-base-url, we should use the document's fallback base URL
+        as base URL when parsing the base element's href attribute.
+
+        * dom/Document.h:
+
+        * html/HTMLBaseElement.cpp:
+        (WebCore::HTMLBaseElement::href const):
+        Per https://html.spec.whatwg.org/#dom-base-href, we should use the document's fallback base URL when
+        parsing the base element's href attribute. Also we should return the attribute value if the URL fails
+        parsing, not a null URL.
+
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::openFunc):
+        Keep in sync with HTMLBaseElement::href(), as per comment.
+
</ins><span class="cx"> 2021-08-10  Kimmo Kinnunen  <kkinnunen@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Scripts/generate-derived-sources.sh: line 19: [: binary operator expected while building Source/WebKit
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp    2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/dom/Document.cpp       2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -3406,6 +3406,30 @@
</span><span class="cx">     updateBaseURL();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// https://html.spec.whatwg.org/#fallback-base-url
+URL Document::fallbackBaseURL() const
+{
+    // The documentURI attribute is read-only from JavaScript, but writable from Objective C, so we need to retain
+    // this fallback behavior. We use a null base URL, since the documentURI attribute is an arbitrary string
+    // and DOM 3 Core does not specify how it should be resolved.
+    auto documentURL = URL({ }, documentURI());
+
+    if (documentURL.isAboutSrcDoc()) {
+        if (auto* parent = parentDocument())
+            return parent->baseURL();
+    }
+
+    if (documentURL.isAboutBlank()) {
+        auto* creator = parentDocument();
+        if (!creator && frame() && frame()->loader().opener())
+            creator = frame()->loader().opener()->document();
+        if (creator)
+            return creator->baseURL();
+    }
+
+    return documentURL;
+}
+
</ins><span class="cx"> void Document::updateBaseURL()
</span><span class="cx"> {
</span><span class="cx">     // DOM 3 Core: When the Document supports the feature "HTML" [DOM Level 2 HTML], the base URI is computed using
</span><span class="lines">@@ -3415,21 +3439,9 @@
</span><span class="cx">         m_baseURL = m_baseElementURL;
</span><span class="cx">     else if (!m_baseURLOverride.isEmpty())
</span><span class="cx">         m_baseURL = m_baseURLOverride;
</span><del>-    else {
-        // The documentURI attribute is read-only from JavaScript, but writable from Objective C, so we need to retain
-        // this fallback behavior. We use a null base URL, since the documentURI attribute is an arbitrary string
-        // and DOM 3 Core does not specify how it should be resolved.
-        m_baseURL = URL({ }, documentURI());
</del><ins>+    else
+        m_baseURL = fallbackBaseURL();
</ins><span class="cx"> 
</span><del>-        if (m_baseURL.isAboutBlank()) {
-            auto* creator = parentDocument();
-            if (!creator && frame() && frame()->loader().opener())
-                creator = frame()->loader().opener()->document();
-            if (creator)
-                m_baseURL = creator->baseURL();
-        }
-    }
-
</del><span class="cx">     clearSelectorQueryCache();
</span><span class="cx"> 
</span><span class="cx">     if (!m_baseURL.isValid())
</span><span class="lines">@@ -3472,7 +3484,7 @@
</span><span class="cx">     if (href) {
</span><span class="cx">         String strippedHref = stripLeadingAndTrailingHTMLSpaces(*href);
</span><span class="cx">         if (!strippedHref.isEmpty())
</span><del>-            baseElementURL = URL(url(), strippedHref);
</del><ins>+            baseElementURL = URL(fallbackBaseURL(), strippedHref);
</ins><span class="cx">     }
</span><span class="cx">     if (m_baseElementURL != baseElementURL && contentSecurityPolicy()->allowBaseURI(baseElementURL)) {
</span><span class="cx">         if (settings().shouldRestrictBaseURLSchemes() && !SecurityPolicy::isBaseURLSchemeAllowed(baseElementURL))
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h      2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/dom/Document.h 2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1630,6 +1630,8 @@
</span><span class="cx"> 
</span><span class="cx">     String debugDescription() const;
</span><span class="cx"> 
</span><ins>+    URL fallbackBaseURL() const;
+
</ins><span class="cx"> protected:
</span><span class="cx">     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
</span><span class="cx">     WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClassFlags = DefaultDocumentClass, unsigned constructionFlags = 0);
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLBaseElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLBaseElement.cpp (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLBaseElement.cpp    2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/html/HTMLBaseElement.cpp       2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -79,24 +79,20 @@
</span><span class="cx">     return attributeWithoutSynchronization(targetAttr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-URL HTMLBaseElement::href() const
</del><ins>+// https://html.spec.whatwg.org/#dom-base-href
+String HTMLBaseElement::href() const
</ins><span class="cx"> {
</span><del>-    // This does not use the getURLAttribute function because that will resolve relative to the document's base URL;
-    // base elements like this one can be used to set that base URL. Thus we need to resolve relative to the document's
-    // URL and ignore the base URL.
</del><ins>+    AtomString url = attributeWithoutSynchronization(hrefAttr);
+    if (url.isNull())
+        url = emptyAtom();
</ins><span class="cx"> 
</span><del>-    const AtomString& attributeValue = attributeWithoutSynchronization(hrefAttr);
-    if (attributeValue.isNull())
-        return document().url();
-
</del><span class="cx">     // Same logic as openFunc() in XMLDocumentParserLibxml2.cpp. Keep them in sync.
</span><span class="cx">     auto* encoding = document().decoder() ? document().decoder()->encodingForURLParsing() : nullptr;
</span><del>-    URL url(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue), encoding);
</del><ins>+    URL urlRecord(document().fallbackBaseURL(), stripLeadingAndTrailingHTMLSpaces(url), encoding);
+    if (!urlRecord.isValid())
+        return url;
</ins><span class="cx"> 
</span><del>-    if (!url.isValid())
-        return URL();
-
-    return url;
</del><ins>+    return urlRecord.string();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void HTMLBaseElement::setHref(const AtomString& value)
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLBaseElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLBaseElement.h (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLBaseElement.h      2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/html/HTMLBaseElement.h 2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> public:
</span><span class="cx">     static Ref<HTMLBaseElement> create(const QualifiedName&, Document&);
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT URL href() const;
</del><ins>+    WEBCORE_EXPORT String href() const;
</ins><span class="cx">     WEBCORE_EXPORT void setHref(const AtomString&);
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp     2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp        2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -457,7 +457,7 @@
</span><span class="cx">     Document* document = cachedResourceLoader.document();
</span><span class="cx">     // Same logic as HTMLBaseElement::href(). Keep them in sync.
</span><span class="cx">     auto* encoding = (document && document->decoder()) ? document->decoder()->encodingForURLParsing() : nullptr;
</span><del>-    URL url(document ? document->url() : URL(), stripLeadingAndTrailingHTMLSpaces(uri), encoding);
</del><ins>+    URL url(document ? document->fallbackBaseURL() : URL(), stripLeadingAndTrailingHTMLSpaces(uri), encoding);
</ins><span class="cx"> 
</span><span class="cx">     if (!shouldAllowExternalLoad(url))
</span><span class="cx">         return &globalDescriptor;
</span></span></pre></div>
<a id="trunkSourceWebKitLegacymacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKitLegacy/mac/ChangeLog  2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog     2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2021-08-10  Chris Dumez  <cdumez@apple.com>
+
+        Document.baseURI is inaccurate for iframe srcdoc documents
+        https://bugs.webkit.org/show_bug.cgi?id=228933
+
+        Reviewed by Alex Christensen.
+
+        * DOM/DOMHTMLBaseElement.mm:
+        (-[DOMHTMLBaseElement href]):
+
</ins><span class="cx"> 2021-08-09  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Blob URL changes after loading it
</span></span></pre></div>
<a id="trunkSourceWebKitLegacymacDOMDOMHTMLBaseElementmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLBaseElement.mm (280854 => 280855)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLBaseElement.mm  2021-08-10 17:35:35 UTC (rev 280854)
+++ trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLBaseElement.mm     2021-08-10 17:51:30 UTC (rev 280855)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx"> - (NSString *)href
</span><span class="cx"> {
</span><span class="cx">     WebCore::JSMainThreadNullState state;
</span><del>-    return IMPL->href().string();
</del><ins>+    return IMPL->href();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)setHref:(NSString *)newHref
</span></span></pre>
</div>
</div>

</body>
</html>