Fixed issue when using multiple extensions in Router::parseExtensions() could result in undefined index notice by RequestHandlerComponent.

This commit is contained in:
Renan Gonçalves 2011-10-19 15:36:00 +02:00
parent fb4a003522
commit 646b8f1aa0
2 changed files with 16 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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.
*