@@ -696,6 +696,56 @@ public function getQueryStringNormalizationData()
696
696
// Ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
697
697
// PHP also does not include them when building _GET.
698
698
array ('foo=bar&=a=b&=x=y ' , 'foo=bar ' , 'removes params with empty key ' ),
699
+
700
+ // Also reorder nested query string keys
701
+ array ('foo[]=Z&foo[]=A ' , 'foo%5B%5D=A&foo%5B%5D=Z ' , 'reorders values ' ),
702
+ array ('foo[Z]=B&foo[A]=B ' , 'foo%5BA%5D=B&foo%5BZ%5D=B ' , 'reorders keys ' ),
703
+
704
+ array ('utf8=✓ ' , 'utf8=%E2%9C%93 ' , 'encodes UTF-8 ' ),
705
+ );
706
+ }
707
+
708
+ /**
709
+ * @dataProvider getQueryStringNormalizationDataForPhp
710
+ */
711
+ public function testGetQueryStringForPhp ($ query , $ expectedQuery , $ msg )
712
+ {
713
+ $ request = new Request ();
714
+
715
+ $ request ->server ->set ('QUERY_STRING ' , $ query );
716
+ $ this ->assertSame ($ expectedQuery , $ request ->getQueryStringForPhp (), $ msg );
717
+ }
718
+
719
+ public function getQueryStringNormalizationDataForPhp ()
720
+ {
721
+ return array (
722
+ array ('foo ' , 'foo= ' , 'works with valueless parameters ' ),
723
+ array ('foo= ' , 'foo= ' , 'includes a dangling equal sign ' ),
724
+ array ('bar=&foo=bar ' , 'bar=&foo=bar ' , '->works with empty parameters ' ),
725
+ array ('foo=bar&bar= ' , 'bar=&foo=bar ' , 'sorts keys alphabetically ' ),
726
+
727
+ // GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded).
728
+ // PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str.
729
+ array ('him=John%20Doe&her=Jane+Doe ' , 'her=Jane%20Doe&him=John%20Doe ' , 'normalizes spaces in both encodings "%20" and "+" ' ),
730
+
731
+ array ('foo[]=1&foo[]=2 ' , 'foo%5B0%5D=1&foo%5B1%5D=2 ' , 'allows array notation ' ),
732
+ array ('foo=1&foo=2 ' , 'foo=2 ' , 'merges repeated parameters ' ),
733
+ array ('pa%3Dram=foo%26bar%3Dbaz&test=test ' , 'pa%3Dram=foo%26bar%3Dbaz&test=test ' , 'works with encoded delimiters ' ),
734
+ array ('0 ' , '0= ' , 'allows "0" ' ),
735
+ array ('Jane Doe&John%20Doe ' , 'Jane_Doe=&John_Doe= ' , 'normalizes encoding in keys ' ),
736
+ array ('her=Jane Doe&him=John%20Doe ' , 'her=Jane%20Doe&him=John%20Doe ' , 'normalizes encoding in values ' ),
737
+ array ('foo=bar&&&test&& ' , 'foo=bar&test= ' , 'removes unneeded delimiters ' ),
738
+ array ('formula=e=m*c^2 ' , 'formula=e%3Dm%2Ac%5E2 ' , 'correctly treats only the first "=" as delimiter and the next as value ' ),
739
+
740
+ // Ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
741
+ // PHP also does not include them when building _GET.
742
+ array ('foo=bar&=a=b&=x=y ' , 'foo=bar ' , 'removes params with empty key ' ),
743
+
744
+ // Don't reorder nested query string keys
745
+ array ('foo[]=Z&foo[]=A ' , 'foo%5B0%5D=Z&foo%5B1%5D=A ' , 'keeps order of values ' ),
746
+ array ('foo[Z]=B&foo[A]=B ' , 'foo%5BZ%5D=B&foo%5BA%5D=B ' , 'keeps order of keys ' ),
747
+
748
+ array ('utf8=✓ ' , 'utf8=%E2%9C%93 ' , 'encodes UTF-8 ' ),
699
749
);
700
750
}
701
751
0 commit comments