diff options
author | eileencodes <eileencodes@gmail.com> | 2016-08-26 13:12:33 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2016-08-26 13:12:33 -0400 |
commit | 1ec85cf9d8a6ad36c3c40cc08a0c7d8407e4b080 (patch) | |
tree | 79d66d86e8b4b9270a52a742845b0b23ae830f16 | |
parent | f394f3ba763adbd073685a4a3f53b2a3ad71381a (diff) | |
download | rails-1ec85cf9d8a6ad36c3c40cc08a0c7d8407e4b080.tar.gz rails-1ec85cf9d8a6ad36c3c40cc08a0c7d8407e4b080.tar.bz2 rails-1ec85cf9d8a6ad36c3c40cc08a0c7d8407e4b080.zip |
Missing key should throw KeyError
It should not throw a NameError, but should throw a KeyError.
Fixes #26278
-rw-r--r-- | actionpack/lib/action_dispatch/http/headers.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/header_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/headers.rb b/actionpack/lib/action_dispatch/http/headers.rb index d5eef2987d..0528a6ad08 100644 --- a/actionpack/lib/action_dispatch/http/headers.rb +++ b/actionpack/lib/action_dispatch/http/headers.rb @@ -86,7 +86,7 @@ module ActionDispatch @req.fetch_header(env_name(key)) do return default unless default == DEFAULT return yield if block_given? - raise NameError, key + raise KeyError, key end end diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 7a155d70cb..374e618b42 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -158,4 +158,10 @@ class HeaderTest < ActiveSupport::TestCase assert_equal({ "HTTP_REFERER"=>"http://example.com/", "CONTENT_TYPE"=>"text/plain" }, env) end + + test "fetch exception" do + assert_raises KeyError do + @headers.fetch(:some_key_that_doesnt_exist) + end + end end |