aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authormathieuravaux <mathieu.ravaux@gmail.com>2011-02-27 01:52:08 +0100
committerJosé Valim <jose.valim@gmail.com>2011-05-07 23:35:52 +0200
commitfadd1fa3d314639067404403651de52a7d2b72f7 (patch)
tree45c3587562c970f0a5fa13ee2b628bbb560e78ca /actionpack
parent803548c46b32d1be760b21da80477f43b801b8e9 (diff)
downloadrails-fadd1fa3d314639067404403651de52a7d2b72f7.tar.gz
rails-fadd1fa3d314639067404403651de52a7d2b72f7.tar.bz2
rails-fadd1fa3d314639067404403651de52a7d2b72f7.zip
Fixes ticket #6379. Improved the handling of Accept headers containing */*.
`lookup_context#formats=` being too restrictive, "Accept: text/javascript, */*" resulted in [:js, "*/*"] formats instead of [:js, :html]. Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/lookup_context.rb11
-rw-r--r--actionpack/test/template/lookup_context_test.rb5
2 files changed, 12 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 06975ffa2f..02114f46da 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -169,10 +169,13 @@ module ActionView
# Overload formats= to reject ["*/*"] values.
def formats=(values)
- if values && values.size == 1
- value = values.first
- values = nil if value == "*/*"
- values << :html if value == :js
+ if values
+ values.pop if values.last == "*/*"
+ if values.size == 0
+ values = nil
+ elsif values == [:js]
+ values << :html
+ end
end
super(values)
end
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index 5fb1fdc044..e7680bc022 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -51,6 +51,11 @@ class LookupContextTest < ActiveSupport::TestCase
assert_equal Mime::SET, @lookup_context.formats
end
+ test "handles explicitly defined */* formats fallback to :js" do
+ @lookup_context.formats = [:js, Mime::ALL]
+ assert_equal [:js, :html], @lookup_context.formats
+ end
+
test "adds :html fallback to :js formats" do
@lookup_context.formats = [:js]
assert_equal [:js, :html], @lookup_context.formats