Skip to content
Browse files

HTTP::Headers#key? correctly converts

Previously if you were looking for a given key, the header may incorrectly tell you that it did not exist even though it would return a valid value:

```ruby
env     = { "CONTENT_TYPE" => "text/plain" }
headers = ActionDispatch::Http::Headers.new(env)
headers["Content-Type"] 
# => "text/plain"

headers.key?("Content-Type")
# => false
```

This PR fixes that behavior by converting the key before checking for presence
  • Loading branch information...
1 parent 98baa82 commit ca97ec509955d70bde47d337e5086920f0c79b63 @schneems schneems committed
Showing with 5 additions and 1 deletion.
  1. +3 −1 actionpack/lib/action_dispatch/http/headers.rb
  2. +2 −0 actionpack/test/dispatch/header_test.rb
View
4 actionpack/lib/action_dispatch/http/headers.rb
@@ -26,7 +26,9 @@ def []=(key, value)
@env[env_name(key)] = value
end
- def key?(key); @env.key? key; end
+ def key?(key)
+ @env.key? env_name(key)
+ end
alias :include? :key?
def fetch(key, *args, &block)
View
2 actionpack/test/dispatch/header_test.rb
@@ -55,6 +55,8 @@ class HeaderTest < ActiveSupport::TestCase
test "key?" do
assert @headers.key?("CONTENT_TYPE")
assert @headers.include?("CONTENT_TYPE")
+ assert @headers.key?("Content-Type")
+ assert @headers.include?("Content-Type")
end
test "fetch with block" do

0 comments on commit ca97ec5

Please sign in to comment.
Something went wrong with that request. Please try again.