- Revision
- 206168
- Author
- achristen...@apple.com
- Date
- 2016-09-20 13:11:54 -0700 (Tue, 20 Sep 2016)
Log 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):
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206167 => 206168)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-20 20:11:54 UTC (rev 206168)
@@ -1,5 +1,14 @@
2016-09-20 Alex Christensen <achristen...@webkit.org>
+ Make URLSearchParams spec-compliant
+ https://bugs.webkit.org/show_bug.cgi?id=162247
+
+ Reviewed by Chris Dumez and Sam Weinig.
+
+ * web-platform-tests/url/url-constructor-expected.txt:
+
+2016-09-20 Alex Christensen <achristen...@webkit.org>
+
Non-special URLs should have an opaque origin
https://bugs.webkit.org/show_bug.cgi?id=162254
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt (206167 => 206168)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/url-constructor-expected.txt 2016-09-20 20:11:54 UTC (rev 206168)
@@ -1,8 +1,8 @@
PASS URL.searchParams getter
-FAIL URL.searchParams updating, clearing assert_equals: expected "" but got "a=b"
+PASS URL.searchParams updating, clearing
PASS URL.searchParams setter, invalid values
-FAIL URL.searchParams and URL.search setters, update propagation assert_equals: expected "e=f&g=h" but got "a=b&c=d"
+PASS URL.searchParams and URL.search setters, update propagation
PASS Loading data…
PASS Parsing: <http://example .
org> against <http://example.org/foo/bar>
@@ -350,7 +350,7 @@
a
g> against <about:blank>
PASS Parsing: <?a=b&c=d> against <http://example.org/foo/bar>
-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"
+PASS Parsing: <??a=b&c=d> against <http://example.org/foo/bar>
PASS Parsing: <http:> against <http://example.org/foo/bar>
FAIL Parsing: <http:> against <https://example.org/foo/bar> assert_throws: function "function () {
bURL(expected.input, expected.bas..." did not throw
Modified: trunk/Source/WebCore/ChangeLog (206167 => 206168)
--- trunk/Source/WebCore/ChangeLog 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/Source/WebCore/ChangeLog 2016-09-20 20:11:54 UTC (rev 206168)
@@ -1,3 +1,27 @@
+2016-09-20 Alex Christensen <achristen...@webkit.org>
+
+ Make URLSearchParams spec-compliant
+ https://bugs.webkit.org/show_bug.cgi?id=162247
+
+ Reviewed by Chris Dumez and Sam Weinig.
+
+ 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):
+
2016-09-20 Antti Koivisto <an...@apple.com>
Remove AuthorStyleSheets::m_hadActiveLoadingStylesheet bit
Modified: trunk/Source/WebCore/html/DOMURL.cpp (206167 => 206168)
--- trunk/Source/WebCore/html/DOMURL.cpp 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/Source/WebCore/html/DOMURL.cpp 2016-09-20 20:11:54 UTC (rev 206168)
@@ -78,9 +78,17 @@
ec = TypeError;
}
+DOMURL::~DOMURL()
+{
+ if (m_searchParams)
+ m_searchParams->associatedURLDestroyed();
+}
+
void DOMURL::setHref(const String& url)
{
m_url = URL(m_baseURL, url);
+ if (m_searchParams)
+ m_searchParams->updateFromAssociatedURL();
}
void DOMURL::setQuery(const String& query)
@@ -113,9 +121,11 @@
return publicURL.string();
}
-Ref<URLSearchParams> DOMURL::searchParams()
+URLSearchParams& DOMURL::searchParams()
{
- return URLSearchParams::create(m_url.query(), this);
+ if (!m_searchParams)
+ m_searchParams = URLSearchParams::create(search(), this);
+ return *m_searchParams;
}
void DOMURL::revokeObjectURL(ScriptExecutionContext& scriptExecutionContext, const String& urlString)
Modified: trunk/Source/WebCore/html/DOMURL.h (206167 => 206168)
--- trunk/Source/WebCore/html/DOMURL.h 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/Source/WebCore/html/DOMURL.h 2016-09-20 20:11:54 UTC (rev 206168)
@@ -45,6 +45,7 @@
static Ref<DOMURL> create(const String& url, const String& base, ExceptionCode&);
static Ref<DOMURL> create(const String& url, const DOMURL& base, ExceptionCode&);
static Ref<DOMURL> create(const String& url, ExceptionCode&);
+ ~DOMURL();
URL href() const { return m_url; }
void setHref(const String& url);
@@ -51,13 +52,12 @@
void setHref(const String&, ExceptionCode&);
void setQuery(const String&);
- Ref<URLSearchParams> searchParams();
+ URLSearchParams& searchParams();
static String createObjectURL(ScriptExecutionContext&, Blob*);
static void revokeObjectURL(ScriptExecutionContext&, const String&);
static String createPublicURL(ScriptExecutionContext&, URLRegistrable*);
-
private:
DOMURL(const String& url, const String& base, ExceptionCode&);
DOMURL(const String& url, const DOMURL& base, ExceptionCode&);
@@ -65,6 +65,7 @@
URL m_baseURL;
URL m_url;
+ RefPtr<URLSearchParams> m_searchParams;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/html/URLSearchParams.cpp (206167 => 206168)
--- trunk/Source/WebCore/html/URLSearchParams.cpp 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/Source/WebCore/html/URLSearchParams.cpp 2016-09-20 20:11:54 UTC (rev 206168)
@@ -117,4 +117,11 @@
m_associatedURL->setQuery(URLParser::serialize(m_pairs));
}
+void URLSearchParams::updateFromAssociatedURL()
+{
+ ASSERT(m_associatedURL);
+ String search = m_associatedURL->search();
+ m_pairs = search.startsWith('?') ? URLParser::parseURLEncodedForm(StringView(search).substring(1)) : URLParser::parseURLEncodedForm(search);
}
+
+}
Modified: trunk/Source/WebCore/html/URLSearchParams.h (206167 => 206168)
--- trunk/Source/WebCore/html/URLSearchParams.h 2016-09-20 20:05:31 UTC (rev 206167)
+++ trunk/Source/WebCore/html/URLSearchParams.h 2016-09-20 20:11:54 UTC (rev 206168)
@@ -35,6 +35,7 @@
static Ref<URLSearchParams> create(const String& string, DOMURL* associatedURL = nullptr) { return adoptRef(*new URLSearchParams(string, associatedURL)); }
static Ref<URLSearchParams> create(const Vector<std::pair<String, String>>& pairs) { return adoptRef(*new URLSearchParams(pairs)); }
+ void associatedURLDestroyed() { m_associatedURL = nullptr; }
void append(const String& name, const String& value);
void remove(const String& name);
String get(const String& name) const;
@@ -43,6 +44,7 @@
void set(const String& name, const String& value);
String toString();
operator const Vector<std::pair<String, String>>&() { return m_pairs; }
+ void updateFromAssociatedURL();
private:
URLSearchParams(const String&, DOMURL*);
@@ -49,7 +51,7 @@
explicit URLSearchParams(const Vector<std::pair<String, String>>&);
void updateURL();
- RefPtr<DOMURL> m_associatedURL;
+ DOMURL* m_associatedURL;
Vector<std::pair<String, String>> m_pairs;
};