From 863d60c578a8cdc8c9e0c6684d2a2da24b24610f Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 20 Aug 2008 00:22:12 -0500 Subject: [PATCH] Fix IE7+MathPlayer Bug IE7+MathPlayer do *not* like the charset parameter to be set in the Content-Type header. Forcing Rails to omit that parameter is surprisingly difficult. --- app/controllers/application.rb | 23 ++++++++++++++++------- test/functional/application_test.rb | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 5d0720e2..b141ebb8 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -151,17 +151,20 @@ class ApplicationController < ActionController::Base public def set_content_type_header + response.charset = 'utf-8' if %w(atom_with_content atom_with_headlines).include?(action_name) - response.headers['type'] = 'application/atom+xml; charset=UTF-8' + response.content_type = Mime::ATOM elsif %w(tex).include?(action_name) - response.headers['type'] = 'text/plain; charset=UTF-8' - elsif request.env['HTTP_USER_AGENT'] =~ /Validator/ or request.env.include?('HTTP_ACCEPT') && + response.content_type = Mime::TEXT + elsif request.user_agent =~ /Validator/ or request.env.include?('HTTP_ACCEPT') && Mime::Type.parse(request.env["HTTP_ACCEPT"]).include?(Mime::XHTML) - response.headers['type'] = 'application/xhtml+xml; charset=UTF-8' - elsif request.env['HTTP_USER_AGENT'] =~ /MathPlayer/ - response.headers['type'] = 'application/xhtml+xml' + response.content_type = Mime::XHTML + elsif request.user_agent =~ /MathPlayer/ + response.charset = nil + response.content_type = Mime::XHTML + response.extend(MathPlayerHack) else - response.headers['type'] = 'text/html; charset=UTF-8' + response.content_type = Mime::HTML end end @@ -220,6 +223,12 @@ module Mime LOOKUP["application/xhtml+xml"] = XHTML end +module MathPlayerHack + def charset=(encoding) + self.headers["Content-Type"] = "#{content_type || Mime::HTML}" + end +end + module Instiki module VERSION #:nodoc: MAJOR = 0 diff --git a/test/functional/application_test.rb b/test/functional/application_test.rb index e028a052..5530c1b0 100755 --- a/test/functional/application_test.rb +++ b/test/functional/application_test.rb @@ -19,7 +19,24 @@ class ApplicationTest < Test::Unit::TestCase def test_utf8_header get :show, :web => 'wiki1', :id => 'HomePage' - assert_equal 'text/html; charset=UTF-8', @response.headers['type'] + assert_equal 'text/html; charset=utf-8', @response.headers['type'] + end + + def test_mathplayer_mime_type + @request.user_agent = 'MathPlayer' + get :show, :web => 'wiki1', :id => 'HomePage' + assert_equal 'application/xhtml+xml', @response.headers['type'] + end + + def test_validator_mime_type + @request.user_agent = 'Validator' + get :show, :web => 'wiki1', :id => 'HomePage' + assert_equal 'application/xhtml+xml; charset=utf-8', @response.headers['type'] + end + + def test_tex_mime_type + get :tex, :web => 'wiki1', :id => 'HomePage' + assert_equal 'text/plain; charset=utf-8', @response.headers['type'] end def test_connect_to_model_unknown_wiki