Skip to content
This repository

Fix #8086 (BestStandardsSupport rewrites app X-UA-Compatible header) #8093

Merged
merged 1 commit into from over 1 year ago

2 participants

Nikita Afanasenko Carlos Antonio da Silva
Nikita Afanasenko

Now BestStandardsSupport middleware appends it's X-UA-Compatible value to app's value.
Also test for BestStandardsSupport middleware added.

Nikita Afanasenko

Will probably need a 3.2 backport

Carlos Antonio da Silva

Looks good. It needs a changelog entry, thanks!

Nikita Afanasenko Fix #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.
d8c1404
Nikita Afanasenko

@carlosantoniodasilva thanks, done. Do it need a backport?

Carlos Antonio da Silva carlosantoniodasilva commented on the diff November 01, 2012
actionpack/test/dispatch/best_standards_support_test.rb
((10 lines not shown))
  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
2

What happens if you give it false, but has X-UA-Compatible set in the app? Will it override the users' value?

Anyway, don't worry, the middleware is not added if the config is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Carlos Antonio da Silva carlosantoniodasilva merged commit 69cebae into from November 01, 2012
Carlos Antonio da Silva carlosantoniodasilva closed this November 01, 2012
Carlos Antonio da Silva

@nikitug I think it can be backported without problem yeah, but we will need to wait until 3.2.9 is released. Thanks!

Carlos Antonio da Silva

Backported in 90a5ec7, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 01, 2012
Nikita Afanasenko Fix #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.
d8c1404
This page is out of date. Refresh to see the latest.
5  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,10 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  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
+
3 8
 *   `date_select` helper accepts `with_css_classes: true` to add css classes similar with type
4 9
     of generated select tags.
5 10
 
8  actionpack/lib/action_dispatch/middleware/best_standards_support.rb
@@ -15,7 +15,13 @@ def initialize(app, type = true)
15 15
 
16 16
     def call(env)
17 17
       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
+
19 25
       [status, headers, body]
20 26
     end
21 27
   end
34  actionpack/test/dispatch/best_standards_support_test.rb
... ...
@@ -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
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.