@@ -510,6 +510,11 @@ public function testGetQueryString()
510
510
{
511
511
$ request = new Request ();
512
512
513
+ $ this ->assertNull ($ request ->getQueryString (), '->getQueryString() returns null for non-existent query string ' );
514
+
515
+ $ request ->server ->set ('QUERY_STRING ' , '' );
516
+ $ this ->assertNull ($ request ->getQueryString (), '->getQueryString() returns null for empty query string ' );
517
+
513
518
$ request ->server ->set ('QUERY_STRING ' , 'foo ' );
514
519
$ this ->assertEquals ('foo ' , $ request ->getQueryString (), '->getQueryString() works with valueless parameters ' );
515
520
@@ -523,13 +528,38 @@ public function testGetQueryString()
523
528
$ this ->assertEquals ('bar=&foo=bar ' , $ request ->getQueryString (), '->getQueryString() sorts keys alphabetically ' );
524
529
525
530
$ request ->server ->set ('QUERY_STRING ' , 'him=John%20Doe&her=Jane+Doe ' );
526
- $ this ->assertEquals ('her=Jane%2BDoe&him=John%20Doe ' , $ request ->getQueryString (), '->getQueryString() normalizes encoding ' );
531
+ // GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded).
532
+ // PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str.
533
+ $ this ->assertSame ('her=Jane%20Doe&him=John%20Doe ' , $ request ->getQueryString (), '->getQueryString() normalizes spaces in both encodings "%20" and "+" ' );
527
534
528
535
$ request ->server ->set ('QUERY_STRING ' , 'foo[]=1&foo[]=2 ' );
529
536
$ this ->assertEquals ('foo%5B%5D=1&foo%5B%5D=2 ' , $ request ->getQueryString (), '->getQueryString() allows array notation ' );
530
537
531
538
$ request ->server ->set ('QUERY_STRING ' , 'foo=1&foo=2 ' );
532
539
$ this ->assertEquals ('foo=1&foo=2 ' , $ request ->getQueryString (), '->getQueryString() allows repeated parameters ' );
540
+
541
+ $ request ->server ->set ('QUERY_STRING ' , 'pa%3Dram=foo%26bar%3Dbaz&test=test ' );
542
+ $ this ->assertSame ('pa%3Dram=foo%26bar%3Dbaz&test=test ' , $ request ->getQueryString (), '->getQueryString() works with encoded delimiters ' );
543
+
544
+ $ request ->server ->set ('QUERY_STRING ' , '0 ' );
545
+ $ this ->assertSame ('0 ' , $ request ->getQueryString (), '->getQueryString() allows "0" ' );
546
+
547
+ $ request ->server ->set ('QUERY_STRING ' , 'Jane Doe&John%20Doe ' );
548
+ $ this ->assertSame ('Jane%20Doe&John%20Doe ' , $ request ->getQueryString (), '->getQueryString() normalizes encoding in keys ' );
549
+
550
+ $ request ->server ->set ('QUERY_STRING ' , 'her=Jane Doe&him=John%20Doe ' );
551
+ $ this ->assertSame ('her=Jane%20Doe&him=John%20Doe ' , $ request ->getQueryString (), '->getQueryString() normalizes encoding in values ' );
552
+
553
+ $ request ->server ->set ('QUERY_STRING ' , 'foo=bar&&&test&& ' );
554
+ $ this ->assertSame ('foo=bar&test ' , $ request ->getQueryString (), '->getQueryString() removes unneeded delimiters ' );
555
+
556
+ $ request ->server ->set ('QUERY_STRING ' , 'formula=e=m*c^2 ' );
557
+ $ this ->assertSame ('formula=e%3Dm%2Ac%5E2 ' , $ request ->getQueryString (), '->getQueryString() correctly treats only the first "=" as delimiter and the next as value ' );
558
+
559
+ $ request ->server ->set ('QUERY_STRING ' , 'foo=bar&=a=b&=x=y ' );
560
+ // Ignore pairs with empty key, even if there was a value, e.g. "=value", as such nameless values cannot be retrieved anyway.
561
+ // PHP also does not include them when building _GET.
562
+ $ this ->assertSame ('foo=bar ' , $ request ->getQueryString (), '->getQueryString() removes params with empty key ' );
533
563
}
534
564
535
565
/**
0 commit comments