Commit fce50c0b authored by webchick's avatar webchick

Issue #1716790 by attiks, sun, chx, mcjim: Fixed iOS 4 and Android 2.3 and...

Issue #1716790 by attiks, sun, chx, mcjim: Fixed iOS 4 and Android 2.3 and below (webkit based browsers) return 'Unsupported Media Type' on XML in stock 8.x.
parent 8deaba40
......@@ -41,11 +41,21 @@ public function getContentType(Request $request) {
return 'ajax';
}
// Check all formats, it HTML is found return it.
$first_found_format = FALSE;
foreach ($request->getAcceptableContentTypes() as $mime_type) {
$format = $request->getFormat($mime_type);
if (!is_null($format)) {
if ($format === 'html') {
return $format;
}
if (!is_null($format) && !$first_found_format) {
$first_found_format = $format;
}
}
// No HTML found, return first found.
if ($first_found_format) {
return $first_found_format;
}
// Do HTML last so that it always wins.
......
<?php
/**
* @file
* Contains Drupal\system\Tests\DrupalKernel\ContentNegotiationTest.
*/
namespace Drupal\system\Tests\DrupalKernel;
use Drupal\simpletest\WebTestBase;
/**
* Tests content negotation.
*/
class ContentNegotiationTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Content negotiation',
'description' => 'Tests content negotiation.',
'group' => 'DrupalKernel',
);
}
/**
* Verifies HTML responses for bogus Accept headers.
*
* Drupal does not fully support older browsers, but a page output is still
* expected.
*
* @see http://drupal.org/node/1716790
*/
function testBogusAcceptHeader() {
$tests = array(
// @see https://bugs.webkit.org/show_bug.cgi?id=27267
'Firefox 3.5 (2009)' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'IE8 (2009)' => 'image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*',
'Opera (2009)' => 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
'Chrome (2009)' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
// @see https://github.com/symfony/symfony/pull/564
'Firefox 3.6 (2010)' => 'text/html,application/xhtml+xml,application/json,application/xml;q=0.9,*/*;q=0.8',
'Safari (2010)' => '*/*',
'Opera (2010)' => 'image/jpeg,image/gif,image/x-xbitmap,text/html,image/webp,image/png,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.1',
// @see http://drupal.org/node/1716790
'Safari (2010), iOS 4.2.1 (2012)' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Android #1 (2012)' => 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Android #2 (2012)' => 'text/xml,text/html,application/xhtml+xml,image/png,text/plain,*/*;q=0.8',
);
foreach ($tests as $case => $header) {
$this->drupalGet('', array(), array('Accept: ' . $header));
$this->assertNoText('Unsupported Media Type', '"Unsupported Media Type" not found for ' . $case);
$this->assertText(t('Log in'), '"Log in" found for ' . $case);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment