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