Changeset 266748 in webkit


Ignore:
Timestamp:
Sep 8, 2020 2:08:46 PM (4 years ago)
Author:
achristensen@apple.com
Message:

new URL("#") should throw an error
https://bugs.webkit.org/show_bug.cgi?id=216115

Reviewed by Yusuke Suzuki and Darin Adler.

Source/WebCore:

This aligns the DOM URL object with the specification and Firefox.
Covered by adding to fast/dom/DOMURL/url-constructor.html.

  • html/DOMURL.cpp:

(WebCore::DOMURL::create):

  • html/DOMURL.h:

LayoutTests:

  • fast/dom/DOMURL/url-constructor-expected.txt:
  • fast/dom/DOMURL/url-constructor.html:
  • inspector/unit-tests/url-utilities.html:
  • inspector/unit-tests/url-utilities-expected.txt:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r266746 r266748  
     12020-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        new URL("#") should throw an error
     4        https://bugs.webkit.org/show_bug.cgi?id=216115
     5
     6        Reviewed by Yusuke Suzuki and Darin Adler.
     7
     8        * fast/dom/DOMURL/url-constructor-expected.txt:
     9        * fast/dom/DOMURL/url-constructor.html:
     10        * inspector/unit-tests/url-utilities.html:
     11        * inspector/unit-tests/url-utilities-expected.txt:
     12
    1132020-09-08  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/fast/dom/DOMURL/url-constructor-expected.txt

    r163208 r266748  
    88One-parameter constructor - invalid URL should throw
    99PASS url = new URL("%^$#") threw exception TypeError: Type error.
     10PASS url = new URL("#") threw exception TypeError: Type error.
    1011One-parameter constructor - relative URL not valid against default base
    1112PASS url = new URL("foobar") threw exception TypeError: Type error.
  • trunk/LayoutTests/fast/dom/DOMURL/url-constructor.html

    r163208 r266748  
    1616debug("One-parameter constructor - invalid URL should throw");
    1717shouldThrow('url = new URL("%^$#")');
     18shouldThrow('url = new URL("#")');
    1819
    1920debug("One-parameter constructor - relative URL not valid against default base");
  • trunk/LayoutTests/inspector/unit-tests/url-utilities-expected.txt

    r249504 r266748  
    500500PASS: Removing fragment of 'http://example.com/path?#' should be 'http://example.com/path?'.
    501501PASS: Removing fragment of 'http://example.com/path/?#' should be 'http://example.com/path/?'.
    502 PASS: Removing fragment of '#hash' should be 'about:blank'.
     502PASS: Removing fragment of 'about:blank#hash' should be 'about:blank'.
    503503PASS: Removing fragment of 'invalid' should be 'invalid'.
    504504
  • trunk/LayoutTests/inspector/unit-tests/url-utilities.html

    r249504 r266748  
    574574            test("http://example.com/path/?#", "http://example.com/path/?");
    575575
    576             test("#hash", "about:blank");
     576            test(new URL("#hash", "about:blank"), "about:blank");
    577577            test("invalid", "invalid");
    578578
  • trunk/Source/WebCore/ChangeLog

    r266746 r266748  
     12020-09-08  Alex Christensen  <achristensen@webkit.org>
     2
     3        new URL("#") should throw an error
     4        https://bugs.webkit.org/show_bug.cgi?id=216115
     5
     6        Reviewed by Yusuke Suzuki and Darin Adler.
     7
     8        This aligns the DOM URL object with the specification and Firefox.
     9        Covered by adding to fast/dom/DOMURL/url-constructor.html.
     10
     11        * html/DOMURL.cpp:
     12        (WebCore::DOMURL::create):
     13        * html/DOMURL.h:
     14
    1152020-09-08  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebCore/html/DOMURL.cpp

    r266010 r266748  
    4848ExceptionOr<Ref<DOMURL>> DOMURL::create(const String& url, const URL& base)
    4949{
    50     if (!base.isValid())
    51         return Exception { TypeError };
     50    ASSERT(base.isValid() || base.isNull());
    5251    URL completeURL { base, url };
    5352    if (!completeURL.isValid())
     
    5857ExceptionOr<Ref<DOMURL>> DOMURL::create(const String& url, const String& base)
    5958{
    60     return create(url, base.isNull() ? aboutBlankURL() : URL { URL { }, base });
     59    URL baseURL { URL { }, base };
     60    if (!base.isNull() && !baseURL.isValid())
     61        return Exception { TypeError };
     62    return create(url, baseURL);
    6163}
    6264
  • trunk/Source/WebCore/html/DOMURL.h

    r266010 r266748  
    4242    static ExceptionOr<Ref<DOMURL>> create(const String& url, const String& base);
    4343    static ExceptionOr<Ref<DOMURL>> create(const String& url, const DOMURL& base);
    44     static ExceptionOr<Ref<DOMURL>> create(const String& url, const URL& base);
    4544    ~DOMURL();
    4645
     
    5958
    6059private:
     60    static ExceptionOr<Ref<DOMURL>> create(const String& url, const URL& base);
    6161    DOMURL(URL&& completeURL, const URL& baseURL);
    6262
Note: See TracChangeset for help on using the changeset viewer.