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 authored and jekyllbot committed Aug 9, 2017
1 parent 3fab69e commit bd31986
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 @@ -72,7 +72,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 @@ -106,7 +106,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 @@ -15,6 +15,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 bd31986

Please sign in to comment.