Title: [210915] trunk
Revision
210915
Author
[email protected]
Date
2017-01-18 23:45:30 -0800 (Wed, 18 Jan 2017)

Log Message

Implement URLSearchParams's sort()
https://bugs.webkit.org/show_bug.cgi?id=167154

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/url/urlsearchparams-sort-expected.txt: Added.
* web-platform-tests/url/urlsearchparams-sort.html: Added.

Source/WebCore:

Test: imported/w3c/web-platform-tests/url/urlsearchparams-sort.html

* html/URLSearchParams.cpp:
(WebCore::URLSearchParams::sort):
* html/URLSearchParams.h:
* html/URLSearchParams.idl:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (210914 => 210915)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-01-19 07:13:54 UTC (rev 210914)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-01-19 07:45:30 UTC (rev 210915)
@@ -1,3 +1,13 @@
+2017-01-18  Alex Christensen  <[email protected]>
+
+        Implement URLSearchParams's sort()
+        https://bugs.webkit.org/show_bug.cgi?id=167154
+
+        Reviewed by Sam Weinig.
+
+        * web-platform-tests/url/urlsearchparams-sort-expected.txt: Added.
+        * web-platform-tests/url/urlsearchparams-sort.html: Added.
+
 2017-01-18  Youenn Fablet  <[email protected]>
 
         Reject fetch promise in case of ReadableStream upload

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort-expected.txt (0 => 210915)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort-expected.txt	2017-01-19 07:45:30 UTC (rev 210915)
@@ -0,0 +1,10 @@
+
+PASS Parse and sort: z=b&a=b&z=a&a=a 
+PASS URL parse and sort: z=b&a=b&z=a&a=a 
+PASS Parse and sort: �=x&&�=a 
+PASS URL parse and sort: �=x&&�=a 
+PASS Parse and sort: ffi&🌈 
+PASS URL parse and sort: ffi&🌈 
+PASS Parse and sort: é&e�&é 
+PASS URL parse and sort: é&e�&é 
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort.html (0 => 210915)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort.html	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-sort.html	2017-01-19 07:45:30 UTC (rev 210915)
@@ -0,0 +1,46 @@
+<!doctype html>
+<meta charset="utf8">
+<script src=""
+<script src=""
+<div id=log></div>
+<script>
+[
+  {
+    "input": "z=b&a=b&z=a&a=a",
+    "output": [["a", "b"], ["a", "a"], ["z", "b"], ["z", "a"]]
+  },
+  {
+    "input": "\uFFFD=x&\uFFFC&\uFFFD=a",
+    "output": [["\uFFFC", ""], ["\uFFFD", "x"], ["\uFFFD", "a"]]
+  },
+  {
+    "input": "ffi&🌈", // 🌈 > code point, but < code unit because two code units
+    "output": [["🌈", ""], ["ffi", ""]]
+  },
+  {
+    "input": "é&e\uFFFD&e\u0301",
+    "output": [["e\u0301", ""], ["e\uFFFD", ""], ["é", ""]]
+  }
+].forEach((val) => {
+  test(() => {
+    let params = new URLSearchParams(val.input),
+        i = 0
+    params.sort()
+    for(let param of params) {
+      assert_array_equals(param, val.output[i])
+      i++
+    }
+  }, "Parse and sort: " + val.input)
+
+  test(() => {
+    let url = "" URL("?" + val.input, "https://example/")
+    url.searchParams.sort()
+    let params = new URLSearchParams(url.search),
+        i = 0
+    for(let param of params) {
+      assert_array_equals(param, val.output[i])
+      i++
+    }
+  }, "URL parse and sort: " + val.input)
+})
+</script>

Modified: trunk/Source/WebCore/ChangeLog (210914 => 210915)


--- trunk/Source/WebCore/ChangeLog	2017-01-19 07:13:54 UTC (rev 210914)
+++ trunk/Source/WebCore/ChangeLog	2017-01-19 07:45:30 UTC (rev 210915)
@@ -1,3 +1,17 @@
+2017-01-18  Alex Christensen  <[email protected]>
+
+        Implement URLSearchParams's sort()
+        https://bugs.webkit.org/show_bug.cgi?id=167154
+
+        Reviewed by Sam Weinig.
+
+        Test: imported/w3c/web-platform-tests/url/urlsearchparams-sort.html
+
+        * html/URLSearchParams.cpp:
+        (WebCore::URLSearchParams::sort):
+        * html/URLSearchParams.h:
+        * html/URLSearchParams.idl:
+
 2017-01-18  Yoav Weiss  <[email protected]>
 
         Add Link header support for preload.

Modified: trunk/Source/WebCore/html/URLSearchParams.cpp (210914 => 210915)


--- trunk/Source/WebCore/html/URLSearchParams.cpp	2017-01-19 07:13:54 UTC (rev 210914)
+++ trunk/Source/WebCore/html/URLSearchParams.cpp	2017-01-19 07:45:30 UTC (rev 210915)
@@ -59,6 +59,14 @@
     return false;
 }
 
+void URLSearchParams::sort()
+{
+    std::stable_sort(m_pairs.begin(), m_pairs.end(), [] (const std::pair<String, String>& a, const std::pair<String, String>& b) {
+        return WTF::codePointCompareLessThan(a.first, b.first);
+    });
+    updateURL();
+}
+
 void URLSearchParams::set(const String& name, const String& value)
 {
     for (auto& pair : m_pairs) {

Modified: trunk/Source/WebCore/html/URLSearchParams.h (210914 => 210915)


--- trunk/Source/WebCore/html/URLSearchParams.h	2017-01-19 07:13:54 UTC (rev 210914)
+++ trunk/Source/WebCore/html/URLSearchParams.h	2017-01-19 07:45:30 UTC (rev 210915)
@@ -47,6 +47,7 @@
     const Vector<std::pair<String, String>>& pairs() const { return m_pairs; }
     operator const Vector<std::pair<String, String>>&() { return m_pairs; }
     void updateFromAssociatedURL();
+    void sort();
 
     class Iterator {
     public:

Modified: trunk/Source/WebCore/html/URLSearchParams.idl (210914 => 210915)


--- trunk/Source/WebCore/html/URLSearchParams.idl	2017-01-19 07:13:54 UTC (rev 210914)
+++ trunk/Source/WebCore/html/URLSearchParams.idl	2017-01-19 07:45:30 UTC (rev 210915)
@@ -34,6 +34,9 @@
     sequence<USVString> getAll(USVString name);
     boolean has(USVString name);
     void set(USVString name, USVString value);
+
+    void sort();
+
     iterable<USVString, USVString>;
 
     // FIXME: This should just be stringifier once that is supported in the bindings generator
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to