Bug 23310: Setting an absolute path (/abs) on an <iframe> with no src doesn...
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2009 21:40:24 +0000 (21:40 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2009 21:40:24 +0000 (21:40 +0000)
        <https://bugs.webkit.org/show_bug.cgi?id=23310>

        Reviewed by Darin Adler.

WebCore:

        Test: fast/frames/iframe-no-src-set-location.html

        * dom/Document.cpp:
        (WebCore::Document::completeURL): If m_baseURL is empty or is
        about:blank and we have a parent document, use the parent
        document's URL for the base when completing a new URL.

LayoutTests:

        * fast/frames/iframe-no-src-set-location-expected.txt: Added.
        * fast/frames/iframe-no-src-set-location.html: Added.
        * fast/frames/resources/iframe-no-src-set-location-pass.html: Copied from LayoutTests/fast/dom/Document/early-document-access-expected.txt.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@41953 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/frames/iframe-no-src-set-location-expected.txt [new file with mode: 0644]
LayoutTests/fast/frames/iframe-no-src-set-location.html [new file with mode: 0644]
LayoutTests/fast/frames/resources/iframe-no-src-set-location-pass.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.cpp

index 4fc4ee1..d4f2921 100644 (file)
@@ -1,3 +1,15 @@
+2009-03-24  David Kilzer  <ddkilzer@apple.com>
+
+        Bug 23310: Setting an absolute path (/abs) on an <iframe> with no src doesn't resolve the URL properly
+
+        <https://bugs.webkit.org/show_bug.cgi?id=23310>
+
+        Reviewed by Darin Adler.
+
+        * fast/frames/iframe-no-src-set-location-expected.txt: Added.
+        * fast/frames/iframe-no-src-set-location.html: Added.
+        * fast/frames/resources/iframe-no-src-set-location-pass.html: Copied from LayoutTests/fast/dom/Document/early-document-access-expected.txt.
+
 2009-03-24  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dave Hyatt
diff --git a/LayoutTests/fast/frames/iframe-no-src-set-location-expected.txt b/LayoutTests/fast/frames/iframe-no-src-set-location-expected.txt
new file mode 100644 (file)
index 0000000..79ac0dc
--- /dev/null
@@ -0,0 +1,11 @@
+This tests that an iframe with no src attribute uses the parent document's URL as a base when resolving non-fully-qualified URLs set by JavaScript.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.getElementById('theFrame').contentDocument.baseURI is 'about:blank'
+PASS document.getElementById('theFrame').contentDocument.body.innerHTML is 'PASS\n'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/frames/iframe-no-src-set-location.html b/LayoutTests/fast/frames/iframe-no-src-set-location.html
new file mode 100644 (file)
index 0000000..ee38b84
--- /dev/null
@@ -0,0 +1,44 @@
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="../js/resources/js-test-post-function.js"></script>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+}
+
+var iframeHasLoadedFirstPage = false;
+
+function runTest()
+{
+    if (!iframeHasLoadedFirstPage) {
+        iframeHasLoadedFirstPage = true;
+
+        shouldBe("document.getElementById('theFrame').contentDocument.baseURI", "'about:blank'");
+        var iframe = document.getElementById('theFrame');
+        iframe.src = "javascript:document.location.replace('./resources/iframe-no-src-set-location-pass.html')";
+    } else {
+        shouldBe("document.getElementById('theFrame').contentDocument.body.innerHTML", "'PASS\\n'");
+
+        isSuccessfullyParsed();
+
+        if (window.layoutTestController) {
+            layoutTestController.notifyDone();
+        }
+    }
+}
+
+</script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("This tests that an iframe with no src attribute uses the parent document's URL as a base when resolving non-fully-qualified URLs set by JavaScript.");
+var successfullyParsed = true;
+</script>
+<iframe id="theFrame" onload="runTest()"></iframe>
+</body>
+</html>
diff --git a/LayoutTests/fast/frames/resources/iframe-no-src-set-location-pass.html b/LayoutTests/fast/frames/resources/iframe-no-src-set-location-pass.html
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
index d8ca20e..5e938aa 100644 (file)
@@ -1,3 +1,18 @@
+2009-03-24  David Kilzer  <ddkilzer@apple.com>
+
+        Bug 23310: Setting an absolute path (/abs) on an <iframe> with no src doesn't resolve the URL properly
+
+        <https://bugs.webkit.org/show_bug.cgi?id=23310>
+
+        Reviewed by Darin Adler.
+
+        Test: fast/frames/iframe-no-src-set-location.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::completeURL): If m_baseURL is empty or is
+        about:blank and we have a parent document, use the parent
+        document's URL for the base when completing a new URL.
+
 2009-03-24  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dave Hyatt
index a783917..2acea6c 100644 (file)
@@ -3124,9 +3124,10 @@ KURL Document::completeURL(const String& url) const
     // See also [CSS]StyleSheet::completeURL(const String&)
     if (url.isNull())
         return KURL();
+    const KURL& baseURL = ((m_baseURL.isEmpty() || m_baseURL == blankURL()) && parentDocument()) ? parentDocument()->baseURL() : m_baseURL;
     if (!m_decoder)
-        return KURL(m_baseURL, url);
-    return KURL(m_baseURL, url, m_decoder->encoding());
+        return KURL(baseURL, url);
+    return KURL(baseURL, url, m_decoder->encoding());
 }
 
 void Document::setInPageCache(bool flag)