Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix undefined method `ref' for nil:NilClass for bad accept headers #11000

Merged
merged 1 commit into from

2 participants

@sbeckeriv

One commit for fixing:
Bad HTTP_ACCEPT can cause request.formats to return an array with nil

#10965

Full details at link above.

actionpack/CHANGELOG.md
@@ -14,4 +14,8 @@
*Bryan Ricker*
+* Fix `Mime::Type.parse` when bad accepts header is looked up.
+
+ *Becker*

Can you move that up to the top and fix the indent please? thanks.

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

Done.

Thanks !

@carlosantoniodasilva

Thanks.

@carlosantoniodasilva carlosantoniodasilva merged commit 8ffd139 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 actionpack/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Fix `Mime::Type.parse` when bad accepts header is looked up.
+
+ *Becker*
+
* Element of the `collection_check_boxes` and `collection_radio_buttons` can
optionally contain html attributes as the last element of the array.
View
2  actionpack/lib/action_dispatch/http/mime_type.rb
@@ -175,7 +175,7 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
def parse(accept_header)
if accept_header !~ /,/
accept_header = accept_header.split(PARAMETER_SEPARATOR_REGEXP).first
- parse_trailing_star(accept_header) || [Mime::Type.lookup(accept_header)]
+ parse_trailing_star(accept_header) || [Mime::Type.lookup(accept_header)].compact
else
list, index = AcceptList.new, 0
accept_header.split(',').each do |header|
View
6 actionpack/test/controller/render_test.rb
@@ -1089,6 +1089,12 @@ def test_should_render_formatted_html_erb_template
assert_equal '<test>passed formatted html erb</test>', @response.body
end
+ def test_should_render_formatted_html_erb_template_with_bad_accepts_header
+ @request.env["HTTP_ACCEPT"] = "; a=dsf"
+ get :formatted_xml_erb
+ assert_equal '<test>passed formatted html erb</test>', @response.body
+ end
+
def test_should_render_formatted_html_erb_template_with_faulty_accepts_header
@request.accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*"
get :formatted_xml_erb
Something went wrong with that request. Please try again.