mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 03:22:39 +00:00
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:
parent
55d4fd3be3
commit
6e4493cc14
2 changed files with 17 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -227,6 +228,20 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
|||
$this->RequestHandler->initialize($this->Controller);
|
||||
$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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue