Permalink
Browse files

Fixes ticket #6379. Improved the handling of Accept headers containin…

…g */*.

`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>
  • Loading branch information...
1 parent 803548c commit fadd1fa3d314639067404403651de52a7d2b72f7 @mathieuravaux mathieuravaux committed with josevalim Feb 27, 2011
Showing with 12 additions and 4 deletions.
  1. +7 −4 actionpack/lib/action_view/lookup_context.rb
  2. +5 −0 actionpack/test/template/lookup_context_test.rb
@@ -169,10 +169,13 @@ def freeze_formats(formats, unless_frozen=false) #:nodoc:
# 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
@@ -51,6 +51,11 @@ def teardown
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

0 comments on commit fadd1fa

Please sign in to comment.