Jelajahi Sumber

[HttpFoundation] forced Response content to be string

Fabien Potencier 14 tahun lalu
induk
melakukan
37521b6fd7

+ 2 - 1
src/Symfony/Component/HttpFoundation/Response.php

@@ -170,7 +170,8 @@ class Response
         if (!is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
             throw new \UnexpectedValueException('The Response content must be a string or object implementing __toString(), "'.gettype($content).'" given.');
         }
-        $this->content = $content;
+
+        $this->content = (string) $content;
     }
 
     /**

+ 1 - 1
tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php

@@ -431,7 +431,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
     {
         $response = new Response();
         $response->setContent($content);
-        $this->assertEquals($content, $response->getContent());
+        $this->assertEquals((string) $content, $response->getContent());
     }
 
     /**