@@ -2735,6 +2735,9 @@ interface URLSearchParams {
2735
2735
sequence<USVString> getAll(USVString name);
2736
2736
boolean has(USVString name);
2737
2737
void set(USVString name, USVString value);
2738
+
2739
+ void sort();
2740
+
2738
2741
iterable<USVString, USVString>;
2739
2742
stringifier;
2740
2743
};
@@ -2832,6 +2835,11 @@ method, when invoked, must return the value of the first name-value pair whose n
2832
2835
method, when invoked, must return the values of all name-value pairs whose name is <var> name</var> ,
2833
2836
in <a for=URLSearchParams>list</a> , in list order, and the empty sequence otherwise.
2834
2837
2838
+ <p> The
2839
+ <dfn method for=URLSearchParams><code>has(<var>name</var>)</code></dfn>
2840
+ method, when invoked, must return true if there is a name-value pair whose name is <var> name</var>
2841
+ in <a for=URLSearchParams>list</a> , and false otherwise.
2842
+
2835
2843
<p> The
2836
2844
<dfn method for=URLSearchParams><code>set(<var>name</var>, <var>value</var>)</code></dfn>
2837
2845
method, when invoked, must run these steps:
@@ -2847,10 +2855,37 @@ method, when invoked, must run these steps:
2847
2855
<li><p> Run the <a for=URLSearchParams>update steps</a> .
2848
2856
</ol>
2849
2857
2850
- <p> The
2851
- <dfn method for=URLSearchParams><code>has(<var>name</var>)</code></dfn>
2852
- method, when invoked, must return true if there is a name-value pair whose name is <var> name</var>
2853
- in <a for=URLSearchParams>list</a> , and false otherwise.
2858
+ <hr>
2859
+
2860
+ <div class=example id=example-searchparams-sort>
2861
+ <p> It can be useful to sort the name-value pairs in a {{URLSearchParams}} object, in particular to
2862
+ increase cache hits. This can be accomplished simply through invoking the
2863
+ {{URLSearchParams/sort()}} method:
2864
+
2865
+ <pre><code class=lang-javascript>
2866
+ const url = new URL("https://example.org/?q=🏳️🌈&key=e1f7bc78");
2867
+ url.searchParams.sort();
2868
+ url.search; // "?key=e1f7bc78&q=%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88"</code></pre>
2869
+
2870
+ <p> To avoid altering the original input, e.g., for comparison purposes, construct a new
2871
+ {{URLSearchParams}} object:
2872
+
2873
+ <pre><code class=lang-javascript>
2874
+ const sorted = new URLSearchParams(url.search)
2875
+ sorted.sort()</code></pre>
2876
+ </div>
2877
+
2878
+ <p> The <dfn method for=URLSearchParams><code>sort()</code></dfn> method, when invoked, must run
2879
+ these steps:
2880
+
2881
+ <ol>
2882
+ <li><p> Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of
2883
+ code units. The relative order between name-value pairs with equal names must be preserved.
2884
+
2885
+ <li><p> Run the <a for=URLSearchParams>update steps</a> .
2886
+ </ol>
2887
+
2888
+ <hr>
2854
2889
2855
2890
<p> The <a>value pairs to iterate over</a> are the
2856
2891
<a for=URLSearchParams>list</a> name-value pairs with the key being
@@ -2919,11 +2954,13 @@ Geoff Richards,
2919
2954
Glenn Maynard,
2920
2955
Henri Sivonen,
2921
2956
Ian Hickson,
2957
+ Ilya Grigorik,
2922
2958
Italo A. Casas,
2923
2959
Jakub Gieryluk,
2924
2960
James Graham,
2925
2961
James Manger,
2926
2962
James Ross,
2963
+ Jeffrey Posnick,
2927
2964
Joe Duarte,
2928
2965
Joshua Bell,
2929
2966
Jxck,
@@ -2957,6 +2994,7 @@ Sven Uhlig,
2957
2994
Tab Atkins,
2958
2995
吉野剛史 (Takeshi Yoshino),
2959
2996
Tantek Çelik,
2997
+ Tiancheng "Timothy" Gu,
2960
2998
Tim Berners-Lee,
2961
2999
簡冠庭 (Tim Guan-tin Chien),
2962
3000
Titi_Alone,
0 commit comments