From 47e52bfdca86120cd2ec0d613e14007ec3d50ffe Mon Sep 17 00:00:00 2001 From: Matteo Scaramuccia Date: Tue, 11 Jun 2013 20:15:42 +0200 Subject: [PATCH] MDL-39810 Files: IE doesn't recognize JSON MIME Type (RFC4627). Affected versions: - IE 8+, under Compatibility View. --- lib/outputrenderers.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index da3dbc73be9..9625b93e784 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3344,9 +3344,19 @@ class core_renderer_ajax extends core_renderer { * Prepares the start of an AJAX output. */ public function header() { + // MDL-39810: IE doesn't support JSON MIME type if version < 8 or when it runs in Compatibility View. + $supports_json_contenttype = !check_browser_version('MSIE') || + (check_browser_version('MSIE', 8) && + !(preg_match("/MSIE 7.0/", $_SERVER['HTTP_USER_AGENT']) && preg_match("/Trident\/([0-9\.]+)/", $_SERVER['HTTP_USER_AGENT']))); // unfortunately YUI iframe upload does not support application/json if (!empty($_FILES)) { @header('Content-type: text/plain; charset=utf-8'); + if (!$supports_json_contenttype) { + @header('X-Content-Type-Options: nosniff'); + } + } else if (!$supports_json_contenttype) { + @header('Content-type: text/plain; charset=utf-8'); + @header('X-Content-Type-Options: nosniff'); } else { @header('Content-type: application/json; charset=utf-8'); }