Skip to content

Commit

Permalink
Fix Drop#key? so it can handle a nil argument (#6281)
Browse files Browse the repository at this point in the history
Merge pull request 6281
  • Loading branch information
parkr committed Aug 10, 2017
1 parent c1ac58d commit a7807e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jekyll/drops/drop.rb
Expand Up @@ -71,7 +71,7 @@ def [](key)
def []=(key, val)
if respond_to?("#{key}=")
public_send("#{key}=", val)
elsif respond_to? key
elsif respond_to?(key.to_s)
if self.class.mutable?
@mutations[key] = val
else
Expand Down Expand Up @@ -105,7 +105,7 @@ def key?(key)
if self.class.mutable
@mutations.key?(key)
else
respond_to?(key) || fallback_data.key?(key)
!key.nil? && (respond_to?(key) || fallback_data.key?(key))
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/test_drop.rb
Expand Up @@ -13,6 +13,10 @@ class TestDrop < JekyllUnitTest
@drop = @document.to_liquid
end

should "reject 'nil' key" do
refute @drop.key?(nil)
end

should "raise KeyError if key is not found and no default provided" do
assert_raises KeyError do
@drop.fetch("not_existing_key")
Expand Down

0 comments on commit a7807e6

Please sign in to comment.