diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index ee57e2cb4..e262d7f78 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -140,7 +140,7 @@ class RequestHandlerComponent extends Component { $preferredTypes = $this->mapType($preferred); $similarTypes = array_intersect($extensions, $preferredTypes); if (count($similarTypes) === 1 && !in_array('html', $preferredTypes)) { - $this->ext = $similarTypes[0]; + $this->ext = array_shift($similarTypes); } } diff --git a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php index bf27661c9..865f66c19 100644 --- a/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php @@ -193,6 +193,21 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->assertEquals('json', $this->RequestHandler->ext); } +/** + * Test that RequestHandler sets $this->ext when jQuery sends its wonky-ish headers + * and the application is configured to handle multiplate extensions + * + * @return void + */ + public function testInitializeContentTypeWithjQueryAcceptAndMultiplesExtensions() { + $_SERVER['HTTP_ACCEPT'] = 'application/json, text/javascript, */*; q=0.01'; + $this->assertNull($this->RequestHandler->ext); + Router::parseExtensions('rss', 'json'); + + $this->RequestHandler->initialize($this->Controller); + $this->assertEquals('json', $this->RequestHandler->ext); + } + /** * Test that RequestHandler does not set $this->ext when multple accepts are sent. *