Przeglądaj źródła

ZF-6954
allow empty user-agent

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

sgehrig 16 lat temu
rodzic
commit
2ba7e46e6f
2 zmienionych plików z 41 dodań i 4 usunięć
  1. 20 4
      library/Zend/Soap/Client.php
  2. 21 0
      tests/Zend/Soap/ClientTest.php

+ 20 - 4
library/Zend/Soap/Client.php

@@ -317,8 +317,18 @@ class Zend_Soap_Client
         $options['user_agent']     = $this->getUserAgent();
 
         foreach ($options as $key => $value) {
-            if ($value == null) {
-                unset($options[$key]);
+            /*
+             * ugly hack as I don't know if checking for '=== null'
+             * breaks some other option
+             */
+            if ($key == 'user_agent') {
+                if ($value === null) {
+                    unset($options[$key]);
+                }
+            } else {
+                if ($value == null) {
+                    unset($options[$key]);
+                }
             }
         }
 
@@ -867,17 +877,23 @@ class Zend_Soap_Client
     /**
      * Set the string to use in User-Agent header
      *
-     * @param  string $userAgent
+     * @param  string|null $userAgent
      * @return Zend_Soap_Client
      */
     public function setUserAgent($userAgent)
     {
-        $this->_user_agent = (string)$userAgent;
+        if ($userAgent === null) {
+            $this->_user_agent = null;
+        } else {
+            $this->_user_agent = (string)$userAgent;
+        }
         return $this;
     }
 
     /**
      * Get current string to use in User-Agent header
+     *
+     * @return string|null
      */
     public function getUserAgent()
     {

+ 21 - 0
tests/Zend/Soap/ClientTest.php

@@ -202,6 +202,27 @@ class Zend_Soap_ClientTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('agent4', $options['user_agent']);
     }
 
+    /**
+     * @group ZF-6954
+     */
+    public function testUserAgentAllowsEmptyString()
+    {
+        $client = new Zend_Soap_Client();
+        $this->assertNull($client->getUserAgent());
+        $options = $client->getOptions();
+        $this->assertArrayNotHasKey('user_agent', $options);
+
+        $client->setUserAgent('');
+        $this->assertEquals('', $client->getUserAgent());
+        $options = $client->getOptions();
+        $this->assertEquals('', $options['user_agent']);
+
+        $client->setUserAgent(null);
+        $this->assertNull($client->getUserAgent());
+        $options = $client->getOptions();
+        $this->assertArrayNotHasKey('user_agent', $options);
+    }
+
     public function testGetFunctions()
     {
         $server = new Zend_Soap_Server(dirname(__FILE__) . '/_files/wsdl_example.wsdl');