瀏覽代碼

ZF-11237
Zend_Controller_Response_Abstract::clearRawHeader() behaves incorrect when the header to remove is not present


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23898 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 年之前
父節點
當前提交
9ea983aa26
共有 2 個文件被更改,包括 18 次插入1 次删除
  1. 3 1
      library/Zend/Controller/Response/Abstract.php
  2. 15 0
      tests/Zend/Controller/Response/HttpTest.php

+ 3 - 1
library/Zend/Controller/Response/Abstract.php

@@ -257,7 +257,9 @@ abstract class Zend_Controller_Response_Abstract
         }
 
         $key = array_search($headerRaw, $this->_headersRaw);
-        unset($this->_headersRaw[$key]);
+        if ($key !== false) {
+            unset($this->_headersRaw[$key]);
+        }
 
         return $this;
     }

+ 15 - 0
tests/Zend/Controller/Response/HttpTest.php

@@ -165,6 +165,21 @@ class Zend_Controller_Response_HttpTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($originalHeadersRaw == $updatedHeadersRaw);
     }
 
+       /**
+        * @group ZF-6038
+        */
+    public function testClearRawHeaderThatDoesNotExist()
+    {
+        $this->_response->setRawHeader('HTTP/1.0 404 Not Found');
+        $this->_response->setRawHeader('HTTP/1.0 401 Unauthorized');
+        $originalHeadersRaw = $this->_response->getRawHeaders();
+
+        $this->_response->clearRawHeader('HTTP/1.0 403 Forbidden');
+        $updatedHeadersRaw  = $this->_response->getRawHeaders();
+
+        $this->assertTrue($originalHeadersRaw == $updatedHeadersRaw);
+    }
+
     public function testClearAllHeaders()
     {
         $this->_response->setRawHeader('HTTP/1.0 404 Not Found');