From 90a5ec758dfb9698ecfd59bd08340ffecbda1d75 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 1 Nov 2012 04:42:55 -0700 Subject: Merge pull request #8093 from nikitug/keep_app_x_ua_compatible Fix #8086 (BestStandardsSupport rewrites app X-UA-Compatible header) Conflicts: actionpack/CHANGELOG.md --- actionpack/CHANGELOG.md | 5 ++++ .../middleware/best_standards_support.rb | 8 ++++- .../test/dispatch/best_standards_support_test.rb | 34 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 actionpack/test/dispatch/best_standards_support_test.rb (limited to 'actionpack') diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index fffebd87e9..874fc1ead6 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 3.2.10 (unreleased) ## +* `BestStandardsSupport` middleware now appends it's `X-UA-Compatible` value to app's + returned value if any. Fix #8086 [Backport #8093] + + *Nikita Afanasenko* + * prevent double slashes in engine urls when `Rails.application.default_url_options[:trailing_slash] = true` is set Fix #7842 diff --git a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb index 69adcc419f..d338996240 100644 --- a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb +++ b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb @@ -15,7 +15,13 @@ module ActionDispatch def call(env) status, headers, body = @app.call(env) - headers["X-UA-Compatible"] = @header + + if headers["X-UA-Compatible"] && @header + headers["X-UA-Compatible"] << "," << @header.to_s + else + headers["X-UA-Compatible"] = @header + end + [status, headers, body] end end diff --git a/actionpack/test/dispatch/best_standards_support_test.rb b/actionpack/test/dispatch/best_standards_support_test.rb new file mode 100644 index 0000000000..0737c40a39 --- /dev/null +++ b/actionpack/test/dispatch/best_standards_support_test.rb @@ -0,0 +1,34 @@ +require 'abstract_unit' + +class BestStandardsSupportTest < ActiveSupport::TestCase + def test_with_best_standards_support + _, headers, _ = app(true, {}).call({}) + assert_equal "IE=Edge,chrome=1", headers["X-UA-Compatible"] + end + + def test_with_builtin_best_standards_support + _, headers, _ = app(:builtin, {}).call({}) + assert_equal "IE=Edge", headers["X-UA-Compatible"] + end + + def test_without_best_standards_support + _, headers, _ = app(false, {}).call({}) + assert_equal nil, headers["X-UA-Compatible"] + end + + def test_appends_to_app_headers + app_headers = { "X-UA-Compatible" => "requiresActiveX=true" } + _, headers, _ = app(true, app_headers).call({}) + + expects = "requiresActiveX=true,IE=Edge,chrome=1" + assert_equal expects, headers["X-UA-Compatible"] + end + + private + + def app(type, headers) + app = proc { [200, headers, "response"] } + ActionDispatch::BestStandardsSupport.new(app, type) + end + +end -- cgit v1.2.3