Fix ambiguous content types in RequestHandler.

Treat xhtml + html as content types that should trigger no
response/extension setting.  They are different but similar in
that they both generally use the same HTML templates.

Fixes #2257
This commit is contained in:
mark_story 2011-11-15 22:48:54 -05:00
parent 55d4fd3be3
commit 6e4493cc14
2 changed files with 17 additions and 2 deletions

View file

@ -139,9 +139,9 @@ class RequestHandlerComponent extends Component {
}
$extensions = Router::extensions();
$preferred = array_shift($accept);
$preferredTypes = $this->mapType($preferred);
$preferredTypes = $this->response->mapType($preferred);
$similarTypes = array_intersect($extensions, $preferredTypes);
if (count($similarTypes) === 1 && !in_array('html', $preferredTypes)) {
if (count($similarTypes) === 1 && !in_array('xhtml', $preferredTypes) && !in_array('html', $preferredTypes)) {
$this->ext = array_shift($similarTypes);
}
}

View file

@ -214,6 +214,7 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->RequestHandler->initialize($this->Controller);
$this->assertNull($this->RequestHandler->ext);
}
/**
* Test that ext is not set with multiple accepted content types.
*
@ -228,6 +229,20 @@ class RequestHandlerComponentTest extends CakeTestCase {
$this->assertNull($this->RequestHandler->ext);
}
/**
* Test that ext is not set with confusing android accepts headers.
*
* @return void
*/
public function testInitializeAmbiguousAndroidAccepts() {
$_SERVER['HTTP_ACCEPT'] = 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$this->assertNull($this->RequestHandler->ext);
Router::parseExtensions('html', 'xml');
$this->RequestHandler->initialize($this->Controller);
$this->assertNull($this->RequestHandler->ext);
}
/**
* Test that a type mismatch doesn't incorrectly set the ext
*