Skip to content

Commit d8c1404

Browse files
author
Nikita Afanasenko
committed
Fix rails#8086 (BestStandardsSupport rewrites app X-UA-Compatible header, now appends).
Now `BestStandardsSupport` middleware appends it's `X-UA-Compatible` value to app's value. Also test for `BestStandardsSupport` middleware added.
1 parent b31ea0c commit d8c1404

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

actionpack/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Rails 4.0.0 (unreleased) ##
22

3+
* `BestStandardsSupport` middleware now appends it's `X-UA-Compatible` value to app's
4+
returned value if any. Fix #8086
5+
6+
*Nikita Afanasenko*
7+
38
* `date_select` helper accepts `with_css_classes: true` to add css classes similar with type
49
of generated select tags.
510

actionpack/lib/action_dispatch/middleware/best_standards_support.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ def initialize(app, type = true)
1515

1616
def call(env)
1717
status, headers, body = @app.call(env)
18-
headers["X-UA-Compatible"] = @header
18+
19+
if headers["X-UA-Compatible"] && @header
20+
headers["X-UA-Compatible"] << "," << @header.to_s
21+
else
22+
headers["X-UA-Compatible"] = @header
23+
end
24+
1925
[status, headers, body]
2026
end
2127
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'abstract_unit'
2+
3+
class BestStandardsSupportTest < ActiveSupport::TestCase
4+
def test_with_best_standards_support
5+
_, headers, _ = app(true, {}).call({})
6+
assert_equal "IE=Edge,chrome=1", headers["X-UA-Compatible"]
7+
end
8+
9+
def test_with_builtin_best_standards_support
10+
_, headers, _ = app(:builtin, {}).call({})
11+
assert_equal "IE=Edge", headers["X-UA-Compatible"]
12+
end
13+
14+
def test_without_best_standards_support
15+
_, headers, _ = app(false, {}).call({})
16+
assert_equal nil, headers["X-UA-Compatible"]
17+
end
18+
19+
def test_appends_to_app_headers
20+
app_headers = { "X-UA-Compatible" => "requiresActiveX=true" }
21+
_, headers, _ = app(true, app_headers).call({})
22+
23+
expects = "requiresActiveX=true,IE=Edge,chrome=1"
24+
assert_equal expects, headers["X-UA-Compatible"]
25+
end
26+
27+
private
28+
29+
def app(type, headers)
30+
app = proc { [200, headers, "response"] }
31+
ActionDispatch::BestStandardsSupport.new(app, type)
32+
end
33+
34+
end

0 commit comments

Comments
 (0)