Browse Source

Removing urldecode on http_build_query for request body and request URI - https://github.com/jonnnnyw/php-phantomjs/pull/28

Jonny Wenmoth 11 years ago
parent
commit
b2e6985b73

+ 2 - 2
src/JonnyW/PhantomJs/Message/AbstractRequest.php

@@ -264,7 +264,7 @@ abstract class AbstractRequest implements RequestInterface
         if (count($this->data)) {
         if (count($this->data)) {
 
 
             $url .= false === strpos($url, '?') ? '?' : '&';
             $url .= false === strpos($url, '?') ? '?' : '&';
-            $url .= urldecode(http_build_query($this->data));
+            $url .= http_build_query($this->data);
         }
         }
 
 
         return $url;
         return $url;
@@ -283,7 +283,7 @@ abstract class AbstractRequest implements RequestInterface
             return '';
             return '';
         }
         }
 
 
-        return urldecode(http_build_query($this->getRequestData()));
+        return http_build_query($this->getRequestData());
     }
     }
 
 
     /**
     /**

+ 29 - 3
src/JonnyW/PhantomJs/Tests/Integration/ClientTest.php

@@ -160,6 +160,32 @@ EOF;
         $this->assertEquals(200, $response->getStatus());
         $this->assertEquals(200, $response->getStatus());
     }
     }
 
 
+    /**
+     * Test response contains 200 status code if
+     * request URL contains reserved characters.
+     *
+     * @access public
+     * @return void
+     */
+    public function testResponseContains200StatusCodeIfRequestUrlContainsReservedCharacters()
+    {
+        $client = $this->getClient();
+
+        $request  = $client->getMessageFactory()->createRequest();
+        $response = $client->getMessageFactory()->createResponse();
+
+        $request->setMethod('GET');
+        $request->setUrl('http://jonnyw.kiwi/tests/test-default.php');
+        $request->setRequestData(array(
+            'test1' => 'http://test.com',
+            'test2' => 'A string with an \' ) / # some other invalid [ characters.'
+        ));
+
+        $client->send($request, $response);
+
+        $this->assertEquals(200, $response->getStatus());
+    }
+
     /**
     /**
      * Test response contains valid body if page is
      * Test response contains valid body if page is
      * successfully loaded.
      * successfully loaded.
@@ -268,14 +294,14 @@ EOF;
         $request->setMethod('POST');
         $request->setMethod('POST');
         $request->setUrl('http://jonnyw.kiwi/tests/test-post.php');
         $request->setUrl('http://jonnyw.kiwi/tests/test-post.php');
         $request->setRequestData(array(
         $request->setRequestData(array(
-            'test1' => urlencode('http://test.com'),
-            'test2' => 100,
+            'test1' => 'http://test.com',
+            'test2' => 'A string with an \' ) / # some other invalid [ characters.'
         ));
         ));
 
 
         $client->send($request, $response);
         $client->send($request, $response);
 
 
         $this->assertContains(sprintf('<li>test1=%s</li>', 'http://test.com'), $response->getContent());
         $this->assertContains(sprintf('<li>test1=%s</li>', 'http://test.com'), $response->getContent());
-        $this->assertContains(sprintf('<li>test2=%s</li>', 100), $response->getContent());
+        $this->assertContains(sprintf('<li>test2=%s</li>', 'A string with an \' ) / # some other invalid [ characters.'), $response->getContent());
     }
     }
 
 
     /**
     /**