diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 697bc6c3c3..d659d188ea 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1382,10 +1382,10 @@ class Request public function getRequestFormat($default = 'html') { if (null === $this->format) { - $this->format = $this->get('_format', $default); + $this->format = $this->get('_format'); } - return $this->format; + return null === $this->format ? $default : $this->format; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 9000eb622b..2b852f5956 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1401,6 +1401,11 @@ class RequestTest extends TestCase $request = new Request(); $this->assertEquals('html', $request->getRequestFormat()); + // Ensure that setting different default values over time is possible, + // aka. setRequestFormat determines the state. + $this->assertEquals('json', $request->getRequestFormat('json')); + $this->assertEquals('html', $request->getRequestFormat('html')); + $request = new Request(); $this->assertNull($request->getRequestFormat(null));