Changeset 280855 in webkit


Ignore:
Timestamp:
Aug 10, 2021 10:51:30 AM (11 months ago)
Author:
Chris Dumez
Message:

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:

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:

(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.
Location:
trunk
Files:
1 added
1 deleted
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r280846 r280855  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.baseURI is inaccurate for iframe srcdoc documents
     4        https://bugs.webkit.org/show_bug.cgi?id=228933
     5
     6        Reviewed by Alex Christensen.
     7
     8        Update existing layout test to reflect behavior change.
     9
     10        * fast/dom/HTMLBaseElement/href-attribute-resolves-with-respect-to-document.html: Removed.
     11        * 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.
     12        * http/tests/misc/href-attribute-resolves-with-respect-to-document.html: Added.
     13
    1142021-08-10  Arcady Goldmints-Orlov  <agoldmints@igalia.com>
    215
  • trunk/LayoutTests/http/tests/misc/href-attribute-resolves-with-respect-to-document-expected.txt

    r280854 r280855  
     1Test for HTMLBaseElement's href attribute.
     2
     3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     4
     5
    16PASS endsWith(document.querySelector('base').href, 'foo/bar/') is true
    27PASS endsWith(document.querySelector('base').href, 'foo/bar/foo/bar/') is false
     
    510PASS document.querySelector('base').hasAttribute('href') is false
    611PASS endsWith(document.querySelector('base').href, '/href-attribute-resolves-with-respect-to-document.html') is true
    7 PASS documentWithoutAView.querySelector('base').href is ""
     12PASS documentWithoutAView.querySelector('base').href is "foo/bar/"
    813PASS documentWithoutAView.querySelector('base').href is "http://webkit.org/"
    9 PASS iframe.contentDocument.querySelector('base').href is ""
    10 PASS newWindow.document.querySelector('base').href is ""
     14PASS iframe.contentDocument.querySelector('base').href is "http://127.0.0.1:8000/misc/foo/bar/"
     15PASS newWindow.document.querySelector('base').href is "http://127.0.0.1:8000/misc/foo/bar/"
    1116PASS successfullyParsed is true
    1217
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r280827 r280855  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.baseURI is inaccurate for iframe srcdoc documents
     4        https://bugs.webkit.org/show_bug.cgi?id=228933
     5
     6        Reviewed by Alex Christensen.
     7
     8        Rebaseline WPT tests now that more checks are passing.
     9
     10        * web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt:
     11        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt:
     12        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt:
     13        * web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt:
     14
    1152021-08-10  Cathie Chen  <cathiechen@igalia.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/terminology-0/document-base-url-expected.txt

    r280491 r280855  
    33PASS The fallback base URL of a document containing no base element is the document's address.
    44PASS The fallback base URL of a document whose address is about:blank is the document base URL of the creator document.
    5 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"
     5PASS about:blank with a base element.
    66PASS 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.
    7 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"
     7PASS The base URL of an iframe srcdoc document with a <base> tag should be set by that tag.
    88
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_about_blank-expected.txt

    r203164 r280855  
    11
    22
    3 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 ""
     3PASS base element in about:blank document should resolve against its fallback base URI
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_href_invalid-expected.txt

    r203164 r280855  
    11
    2 FAIL base element with unparseable href should have .href getter return attr value assert_equals: expected "//test:test" but got ""
     2PASS base element with unparseable href should have .href getter return attr value
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-base-element/base_srcdoc-expected.txt

    r203164 r280855  
    11
    22
    3 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 ""
     3PASS base element in srcdoc document should resolve against its fallback base URI
    44
  • trunk/Source/WebCore/ChangeLog

    r280854 r280855  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.baseURI is inaccurate for iframe srcdoc documents
     4        https://bugs.webkit.org/show_bug.cgi?id=228933
     5
     6        Reviewed by Alex Christensen.
     7
     8        Document.baseURI is inaccurate for iframe srcdoc documents:
     9        - https://html.spec.whatwg.org/#fallback-base-url
     10
     11        This aligns our behavior with both Chrome and Firefox.
     12
     13        No new tests, rebaselined existing tests.
     14
     15        * dom/Document.cpp:
     16        (WebCore::Document::fallbackBaseURL const):
     17        (WebCore::Document::updateBaseURL):
     18        Extract "fallback base URL" logic out of updateBaseURL() and into its own function so that
     19        it can be called from other places. Add logic to deal with iframe srcdoc documents to
     20        our "fallback base URL" logic, as per:
     21        - https://html.spec.whatwg.org/#fallback-base-url
     22
     23        (WebCore::Document::processBaseElement):
     24        As per https://html.spec.whatwg.org/#set-the-frozen-base-url, we should use the document's fallback base URL
     25        as base URL when parsing the base element's href attribute.
     26
     27        * dom/Document.h:
     28
     29        * html/HTMLBaseElement.cpp:
     30        (WebCore::HTMLBaseElement::href const):
     31        Per https://html.spec.whatwg.org/#dom-base-href, we should use the document's fallback base URL when
     32        parsing the base element's href attribute. Also we should return the attribute value if the URL fails
     33        parsing, not a null URL.
     34
     35        * xml/parser/XMLDocumentParserLibxml2.cpp:
     36        (WebCore::openFunc):
     37        Keep in sync with HTMLBaseElement::href(), as per comment.
     38
    1392021-08-10  Kimmo Kinnunen  <kkinnunen@apple.com>
    240
  • trunk/Source/WebCore/dom/Document.cpp

    r280772 r280855  
    34073407}
    34083408
     3409// https://html.spec.whatwg.org/#fallback-base-url
     3410URL Document::fallbackBaseURL() const
     3411{
     3412    // The documentURI attribute is read-only from JavaScript, but writable from Objective C, so we need to retain
     3413    // this fallback behavior. We use a null base URL, since the documentURI attribute is an arbitrary string
     3414    // and DOM 3 Core does not specify how it should be resolved.
     3415    auto documentURL = URL({ }, documentURI());
     3416
     3417    if (documentURL.isAboutSrcDoc()) {
     3418        if (auto* parent = parentDocument())
     3419            return parent->baseURL();
     3420    }
     3421
     3422    if (documentURL.isAboutBlank()) {
     3423        auto* creator = parentDocument();
     3424        if (!creator && frame() && frame()->loader().opener())
     3425            creator = frame()->loader().opener()->document();
     3426        if (creator)
     3427            return creator->baseURL();
     3428    }
     3429
     3430    return documentURL;
     3431}
     3432
    34093433void Document::updateBaseURL()
    34103434{
     
    34163440    else if (!m_baseURLOverride.isEmpty())
    34173441        m_baseURL = m_baseURLOverride;
    3418     else {
    3419         // The documentURI attribute is read-only from JavaScript, but writable from Objective C, so we need to retain
    3420         // this fallback behavior. We use a null base URL, since the documentURI attribute is an arbitrary string
    3421         // and DOM 3 Core does not specify how it should be resolved.
    3422         m_baseURL = URL({ }, documentURI());
    3423 
    3424         if (m_baseURL.isAboutBlank()) {
    3425             auto* creator = parentDocument();
    3426             if (!creator && frame() && frame()->loader().opener())
    3427                 creator = frame()->loader().opener()->document();
    3428             if (creator)
    3429                 m_baseURL = creator->baseURL();
    3430         }
    3431     }
     3442    else
     3443        m_baseURL = fallbackBaseURL();
    34323444
    34333445    clearSelectorQueryCache();
     
    34733485        String strippedHref = stripLeadingAndTrailingHTMLSpaces(*href);
    34743486        if (!strippedHref.isEmpty())
    3475             baseElementURL = URL(url(), strippedHref);
     3487            baseElementURL = URL(fallbackBaseURL(), strippedHref);
    34763488    }
    34773489    if (m_baseElementURL != baseElementURL && contentSecurityPolicy()->allowBaseURI(baseElementURL)) {
  • trunk/Source/WebCore/dom/Document.h

    r280772 r280855  
    16311631    String debugDescription() const;
    16321632
     1633    URL fallbackBaseURL() const;
     1634
    16331635protected:
    16341636    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
  • trunk/Source/WebCore/html/HTMLBaseElement.cpp

    r261443 r280855  
    8080}
    8181
    82 URL HTMLBaseElement::href() const
     82// https://html.spec.whatwg.org/#dom-base-href
     83String HTMLBaseElement::href() const
    8384{
    84     // This does not use the getURLAttribute function because that will resolve relative to the document's base URL;
    85     // base elements like this one can be used to set that base URL. Thus we need to resolve relative to the document's
    86     // URL and ignore the base URL.
    87 
    88     const AtomString& attributeValue = attributeWithoutSynchronization(hrefAttr);
    89     if (attributeValue.isNull())
    90         return document().url();
     85    AtomString url = attributeWithoutSynchronization(hrefAttr);
     86    if (url.isNull())
     87        url = emptyAtom();
    9188
    9289    // Same logic as openFunc() in XMLDocumentParserLibxml2.cpp. Keep them in sync.
    9390    auto* encoding = document().decoder() ? document().decoder()->encodingForURLParsing() : nullptr;
    94     URL url(document().url(), stripLeadingAndTrailingHTMLSpaces(attributeValue), encoding);
     91    URL urlRecord(document().fallbackBaseURL(), stripLeadingAndTrailingHTMLSpaces(url), encoding);
     92    if (!urlRecord.isValid())
     93        return url;
    9594
    96     if (!url.isValid())
    97         return URL();
    98 
    99     return url;
     95    return urlRecord.string();
    10096}
    10197
  • trunk/Source/WebCore/html/HTMLBaseElement.h

    r246490 r280855  
    3232    static Ref<HTMLBaseElement> create(const QualifiedName&, Document&);
    3333
    34     WEBCORE_EXPORT URL href() const;
     34    WEBCORE_EXPORT String href() const;
    3535    WEBCORE_EXPORT void setHref(const AtomString&);
    3636
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

    r279370 r280855  
    458458    // Same logic as HTMLBaseElement::href(). Keep them in sync.
    459459    auto* encoding = (document && document->decoder()) ? document->decoder()->encodingForURLParsing() : nullptr;
    460     URL url(document ? document->url() : URL(), stripLeadingAndTrailingHTMLSpaces(uri), encoding);
     460    URL url(document ? document->fallbackBaseURL() : URL(), stripLeadingAndTrailingHTMLSpaces(uri), encoding);
    461461
    462462    if (!shouldAllowExternalLoad(url))
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r280824 r280855  
     12021-08-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.baseURI is inaccurate for iframe srcdoc documents
     4        https://bugs.webkit.org/show_bug.cgi?id=228933
     5
     6        Reviewed by Alex Christensen.
     7
     8        * DOM/DOMHTMLBaseElement.mm:
     9        (-[DOMHTMLBaseElement href]):
     10
    1112021-08-09  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLBaseElement.mm

    r261968 r280855  
    4343{
    4444    WebCore::JSMainThreadNullState state;
    45     return IMPL->href().string();
     45    return IMPL->href();
    4646}
    4747
Note: See TracChangeset for help on using the changeset viewer.