Просмотр исходного кода

ZF-10577: return value on empty but existing headers

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23228 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 лет назад
Родитель
Сommit
ada4806a79

+ 2 - 2
library/Zend/Controller/Request/Http.php

@@ -979,7 +979,7 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
 
         // Try to get it from the $_SERVER array first
         $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
-        if (!empty($_SERVER[$temp])) {
+        if (isset($_SERVER[$temp])) {
             return $_SERVER[$temp];
         }
 
@@ -987,7 +987,7 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
         // Apache
         if (function_exists('apache_request_headers')) {
             $headers = apache_request_headers();
-            if (!empty($headers[$header])) {
+            if (isset($headers[$header])) {
                 return $headers[$header];
             }
             $header = strtolower($header);

+ 10 - 0
tests/Zend/Controller/Request/HttpTest.php

@@ -839,6 +839,16 @@ class Zend_Controller_Request_HttpTest extends PHPUnit_Framework_TestCase
         $pathInfo = $request->getPathInfo();
         $this->assertEquals('/index/index', $pathInfo);
     }
+
+    /**
+     * @group ZF-10577
+     */
+    public function testGetHeaderWithEmptyValueReturnsEmptyString()
+    {
+        $_SERVER['HTTP_X_FOO'] = '';
+        
+        $this->assertSame('', $this->_request->getHeader('X-Foo'));
+    }
 }
 
 // Call Zend_Controller_Request_HttpTest::main() if this source file is executed directly.