浏览代码

Fixing ZF-11283 - trim whitespace from Location header before redirecting

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23863 44c647ce-9c0f-0410-b52a-842ac1e357ba
shahar 14 年之前
父节点
当前提交
a57b4565e8
共有 2 个文件被更改,包括 35 次插入1 次删除
  1. 5 1
      library/Zend/Http/Client.php
  2. 30 0
      tests/Zend/Http/Client/StaticTest.php

+ 5 - 1
library/Zend/Http/Client.php

@@ -1019,6 +1019,10 @@ class Zend_Http_Client
             // If we got redirected, look for the Location header
             if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
 
+                // Avoid problems with buggy servers that add whitespace at the
+                // end of some headers (See ZF-11283)
+                $location = trim($location);
+                
                 // Check whether we send the exact same request again, or drop the parameters
                 // and send a GET request
                 if ($response->getStatus() == 303 ||
@@ -1030,7 +1034,7 @@ class Zend_Http_Client
                 }
 
                 // If we got a well formed absolute URI
-                if (Zend_Uri_Http::check($location)) {
+                if (($scheme = substr($location, 0, 6)) && ($scheme == 'http:/' || $scheme == 'https:')) {
                     $this->setHeaders('host', null);
                     $this->setUri($location);
 

+ 30 - 0
tests/Zend/Http/Client/StaticTest.php

@@ -627,6 +627,36 @@ class Zend_Http_Client_StaticTest extends PHPUnit_Framework_TestCase
 			return;
 		}
     }
+    
+	/**
+     * Test that we can handle trailing space in location header
+     * 
+     * @group ZF-11283
+     * @link http://framework.zend.com/issues/browse/ZF-11283
+     */
+    public function testRedirectWithTrailingSpaceInLocationHeaderZF11283()
+    {
+        $this->_client->setUri('http://example.com/');
+        $this->_client->setAdapter('Zend_Http_Client_Adapter_Test');
+        
+        $adapter = $this->_client->getAdapter(); /* @var $adapter Zend_Http_Client_Adapter_Test */
+        
+        $adapter->setResponse(<<<RESPONSE
+HTTP/1.1 302 Redirect
+Content-Type: text/html; charset=UTF-8
+Location: /test   
+Server: Microsoft-IIS/7.0
+Date: Tue, 19 Apr 2011 11:23:48 GMT
+
+RESPONSE
+        );
+
+        $res = $this->_client->request('GET');
+        
+        $lastUri = $this->_client->getUri();
+        
+        $this->assertEquals("/test", $lastUri->getPath());
+    }
 
     /**
      * Data providers