Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue when using multiple extensions in Router::parseExtensions…

…() could result in undefined index notice by RequestHandlerComponent.
  • Loading branch information...
commit 646b8f1aa04819d3c3cc2ba61fc15ee6b34c922f 1 parent fb4a003
@renan renan authored
View
2  lib/Cake/Controller/Component/RequestHandlerComponent.php
@@ -140,7 +140,7 @@ protected function _setExtension() {
$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);
}
}
View
15 lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php
@@ -194,6 +194,21 @@ public function testInitializeContentTypeWithjQueryAccept() {
}
/**
+ * 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.