Skip to content

Commit

Permalink
Return null type format when format is not know
Browse files Browse the repository at this point in the history
When requesting a controller with the following code with a unknown format:

    def my_action
      respond_to do |format|
        format.json { head :ok }
        format.any { render text: 'Default response' }
      end
    end

we should render the default response instead of raising ActionController::UnknownFormat

Fixes #14462

Conflicts:
	actionpack/CHANGELOG.md
	actionpack/test/controller/mime/respond_with_test.rb
  • Loading branch information
rafaelfranca committed Apr 14, 2014
1 parent 5f768ea commit 320124f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
* Returns null type format when format is not know and controller is using `any`
format block.

Fixes #14462.

*Rafael Mendonça França*

* Only make deeply nested routes shallow when parent is shallow.

Fixes #14684.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/mime_negotiation.rb
Expand Up @@ -129,7 +129,7 @@ def negotiate_mime(order)
end
end

order.include?(Mime::ALL) ? formats.first : nil
order.include?(Mime::ALL) ? format : nil
end

protected
Expand Down
5 changes: 5 additions & 0 deletions actionpack/test/controller/mime/respond_to_test.rb
Expand Up @@ -492,6 +492,11 @@ def test_handle_any_any_xml
assert_equal 'Whatever you ask for, I got it', @response.body
end

def test_handle_any_any_unkown_format
get :handle_any_any, { format: 'php' }
assert_equal 'Whatever you ask for, I got it', @response.body
end

def test_browser_check_with_any_any
@request.accept = "application/json, application/xml"
get :json_xml_or_html
Expand Down

0 comments on commit 320124f

Please sign in to comment.