Skip to content

Commit

Permalink
Fixed issue when using multiple extensions in Router::parseExtensions…
Browse files Browse the repository at this point in the history
…() could result in undefined index notice by RequestHandlerComponent.
  • Loading branch information
renan committed Oct 19, 2011
1 parent fb4a003 commit 646b8f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -193,6 +193,21 @@ public function testInitializeContentTypeWithjQueryAccept() {
$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.
*
Expand Down

0 comments on commit 646b8f1

Please sign in to comment.