Skip to content

Commit

Permalink
When a symbol is passed as a status code it must match a valid http s…
Browse files Browse the repository at this point in the history
…tatus code.
  • Loading branch information
adambutler committed Mar 16, 2016
1 parent 95172a6 commit e6bdee4
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
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,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
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,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 e6bdee4

Please sign in to comment.