Skip to content

Commit

Permalink
Merge pull request #1034 from adambutler/bugfix/response-status-defau…
Browse files Browse the repository at this point in the history
…lt=to-raise-exception

When a symbol is passed as a status code it must match a valid http status code.
  • Loading branch information
rafaelfranca committed Sep 27, 2018
2 parents 2a74e81 + e6bdee4 commit b40583b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rack/utils.rb
Expand Up @@ -563,7 +563,8 @@ def names

def status_code(status)
if status.is_a?(Symbol)
SYMBOL_TO_STATUS_CODE[status] || 500
raise ArgumentError, "Unrecognized status_code symbol" unless SYMBOL_TO_STATUS_CODE[status]
SYMBOL_TO_STATUS_CODE[status]
else
status.to_i
end
Expand Down
6 changes: 6 additions & 0 deletions test/spec_utils.rb
Expand Up @@ -462,6 +462,12 @@ def initialize(*)
Rack::Utils.status_code(:ok).must_equal 200
end

it "raise an error for an invalid symbol" do
assert_raises(ArgumentError, "Unrecognized status_code symbol") do
Rack::Utils.status_code(:foobar)
end
end

it "return rfc2822 format from rfc2822 helper" do
Rack::Utils.rfc2822(Time.at(0).gmtime).must_equal "Thu, 01 Jan 1970 00:00:00 -0000"
end
Expand Down

0 comments on commit b40583b

Please sign in to comment.