Changeset 206168 in webkit


Ignore:
Timestamp:
Sep 20, 2016 1:11:54 PM (8 years ago)
Author:
achristensen@apple.com
Message:

Make URLSearchParams spec-compliant
https://bugs.webkit.org/show_bug.cgi?id=162247

Reviewed by Chris Dumez and Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/url/url-constructor-expected.txt:

Source/WebCore:

Covered by newly-passing web platform tests.

  • html/DOMURL.cpp:

(WebCore::DOMURL::~DOMURL):
(WebCore::DOMURL::setHref):
(WebCore::DOMURL::setQuery):
Update any associated URLSearchParams object when the query could change.
(WebCore::DOMURL::searchParams):
The lifetime of the URLSearchParams was wrong. We were creating a new URLSearchParams each time
URL.searchParams was called, and we should have been creating one the first time and returning the
same instance for subsequent calls. This means the DOMURL must own the URLSearchParams if it is associated,
but if it is not associated, then a URLSearchParams can live on its own.

  • html/DOMURL.h:
  • html/URLSearchParams.h:

(WebCore::URLSearchParams::URLDestroyed):
(WebCore::URLSearchParams::setContents):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r206165 r206168  
     12016-09-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make URLSearchParams spec-compliant
     4        https://bugs.webkit.org/show_bug.cgi?id=162247
     5
     6        Reviewed by Chris Dumez and Sam Weinig.
     7
     8        * web-platform-tests/url/url-constructor-expected.txt:
     9
    1102016-09-20  Alex Christensen  <achristensen@webkit.org>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt

    r206165 r206168  
    11
    22PASS URL.searchParams getter
    3 FAIL URL.searchParams updating, clearing assert_equals: expected "" but got "a=b"
     3PASS URL.searchParams updating, clearing
    44PASS URL.searchParams setter, invalid values
    5 FAIL URL.searchParams and URL.search setters, update propagation assert_equals: expected "e=f&g=h" but got "a=b&c=d"
     5PASS URL.searchParams and URL.search setters, update propagation
    66PASS Loading data…
    77PASS Parsing: <http://example   .
     
    351351g> against <about:blank>
    352352PASS Parsing: <?a=b&c=d> against <http://example.org/foo/bar>
    353 FAIL Parsing: <??a=b&c=d> against <http://example.org/foo/bar> assert_equals: searchParams expected "%3Fa=b&c=d" but got "a=b&c=d"
     353PASS Parsing: <??a=b&c=d> against <http://example.org/foo/bar>
    354354PASS Parsing: <http:> against <http://example.org/foo/bar>
    355355FAIL Parsing: <http:> against <https://example.org/foo/bar> assert_throws: function "function () {
  • trunk/Source/WebCore/ChangeLog

    r206167 r206168  
     12016-09-20  Alex Christensen  <achristensen@webkit.org>
     2
     3        Make URLSearchParams spec-compliant
     4        https://bugs.webkit.org/show_bug.cgi?id=162247
     5
     6        Reviewed by Chris Dumez and Sam Weinig.
     7
     8        Covered by newly-passing web platform tests.
     9
     10        * html/DOMURL.cpp:
     11        (WebCore::DOMURL::~DOMURL):
     12        (WebCore::DOMURL::setHref):
     13        (WebCore::DOMURL::setQuery):
     14        Update any associated URLSearchParams object when the query could change.
     15        (WebCore::DOMURL::searchParams):
     16        The lifetime of the URLSearchParams was wrong.  We were creating a new URLSearchParams each time
     17        URL.searchParams was called, and we should have been creating one the first time and returning the
     18        same instance for subsequent calls.  This means the DOMURL must own the URLSearchParams if it is associated,
     19        but if it is not associated, then a URLSearchParams can live on its own.
     20        * html/DOMURL.h:
     21        * html/URLSearchParams.h:
     22        (WebCore::URLSearchParams::URLDestroyed):
     23        (WebCore::URLSearchParams::setContents):
     24
    1252016-09-20  Antti Koivisto  <antti@apple.com>
    226
  • trunk/Source/WebCore/html/DOMURL.cpp

    r205893 r206168  
    7979}
    8080
     81DOMURL::~DOMURL()
     82{
     83    if (m_searchParams)
     84        m_searchParams->associatedURLDestroyed();
     85}
     86
    8187void DOMURL::setHref(const String& url)
    8288{
    8389    m_url = URL(m_baseURL, url);
     90    if (m_searchParams)
     91        m_searchParams->updateFromAssociatedURL();
    8492}
    8593
     
    114122}
    115123
    116 Ref<URLSearchParams> DOMURL::searchParams()
     124URLSearchParams& DOMURL::searchParams()
    117125{
    118     return URLSearchParams::create(m_url.query(), this);
     126    if (!m_searchParams)
     127        m_searchParams = URLSearchParams::create(search(), this);
     128    return *m_searchParams;
    119129}
    120130   
  • trunk/Source/WebCore/html/DOMURL.h

    r205893 r206168  
    4646    static Ref<DOMURL> create(const String& url, const DOMURL& base, ExceptionCode&);
    4747    static Ref<DOMURL> create(const String& url, ExceptionCode&);
     48    ~DOMURL();
    4849
    4950    URL href() const { return m_url; }
     
    5253    void setQuery(const String&);
    5354
    54     Ref<URLSearchParams> searchParams();
     55    URLSearchParams& searchParams();
    5556
    5657    static String createObjectURL(ScriptExecutionContext&, Blob*);
     
    5859
    5960    static String createPublicURL(ScriptExecutionContext&, URLRegistrable*);
    60 
    6161private:
    6262    DOMURL(const String& url, const String& base, ExceptionCode&);
     
    6666    URL m_baseURL;
    6767    URL m_url;
     68    RefPtr<URLSearchParams> m_searchParams;
    6869};
    6970
  • trunk/Source/WebCore/html/URLSearchParams.cpp

    r205893 r206168  
    118118}
    119119
     120void URLSearchParams::updateFromAssociatedURL()
     121{
     122    ASSERT(m_associatedURL);
     123    String search = m_associatedURL->search();
     124    m_pairs = search.startsWith('?') ? URLParser::parseURLEncodedForm(StringView(search).substring(1)) : URLParser::parseURLEncodedForm(search);
    120125}
     126   
     127}
  • trunk/Source/WebCore/html/URLSearchParams.h

    r205893 r206168  
    3636    static Ref<URLSearchParams> create(const Vector<std::pair<String, String>>& pairs) { return adoptRef(*new URLSearchParams(pairs)); }
    3737
     38    void associatedURLDestroyed() { m_associatedURL = nullptr; }
    3839    void append(const String& name, const String& value);
    3940    void remove(const String& name);
     
    4445    String toString();
    4546    operator const Vector<std::pair<String, String>>&() { return m_pairs; }
     47    void updateFromAssociatedURL();
    4648
    4749private:
     
    5052    void updateURL();
    5153
    52     RefPtr<DOMURL> m_associatedURL;
     54    DOMURL* m_associatedURL;
    5355    Vector<std::pair<String, String>> m_pairs;
    5456};
Note: See TracChangeset for help on using the changeset viewer.