Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'fix-http-request-1' of https://github.com/cogitatio/zf2

…into hotfix/uri-host-validation
  • Loading branch information...
commit 350de78abd52643791f45b9ceebba4a288ec7161 2 parents 881289e + 9f4e579
Matthew Weier O'Phinney authored May 04, 2012
12  library/Zend/Http/Request.php
@@ -175,10 +175,16 @@ public function getMethod()
175 175
     public function setUri($uri)
176 176
     {
177 177
         if (is_string($uri)) {
178  
-            if (!\Zend\Uri\Uri::validateHost($uri)) {
179  
-                throw new Exception\InvalidArgumentException('Invalid URI passed as string');
  178
+            try {
  179
+                $uri = new HttpUri($uri);
  180
+            } catch (Exception\InvalidUriPartException $e) {
  181
+                throw new Exception\InvalidArgumentException(
  182
+                        sprintf('Invalid URI passed as string (%s)', (string) $uri),
  183
+                        $e->getCode(),
  184
+                        $e
  185
+                );
180 186
             }
181  
-        } elseif (!($uri instanceof \Zend\Uri\Http)) {
  187
+        } elseif (!($uri instanceof HttpUri)) {
182 188
             throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
183 189
         }
184 190
         $this->uri = $uri;
22  tests/Zend/Http/RequestTest.php
@@ -82,14 +82,26 @@ public function testRequestCanAlwaysForcesUppecaseMethodName()
82 82
         $this->assertEquals('GET', $request->getMethod());
83 83
     }
84 84
 
85  
-    public function testRequestCanSetAndRetrieveUri()
  85
+    /**
  86
+     * @dataProvider uriDataProvider
  87
+     */
  88
+    public function testRequestCanSetAndRetrieveUri($uri)
86 89
     {
87 90
         $request = new Request();
88  
-        $request->setUri('/foo');
89  
-        $this->assertEquals('/foo', $request->getUri());
  91
+        $request->setUri($uri);
  92
+        $this->assertEquals($uri, $request->getUri());
90 93
         $this->assertInstanceOf('Zend\Uri\Uri', $request->uri());
91  
-        $this->assertEquals('/foo', $request->uri()->toString());
92  
-        $this->assertEquals('/foo', $request->getUri());
  94
+        $this->assertEquals($uri, $request->uri()->toString());
  95
+        $this->assertEquals($uri, $request->getUri());
  96
+    }
  97
+
  98
+    public function uriDataProvider()
  99
+    {
  100
+        return array(
  101
+            array('/foo'),
  102
+            array('/foo#test'),
  103
+            array('/hello?what=true#noway')
  104
+        );
93 105
     }
94 106
 
95 107
     public function testRequestSetUriWillThrowExceptionOnInvalidArgument()

0 notes on commit 350de78

Please sign in to comment.
Something went wrong with that request. Please try again.