diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index d98d28a0..d318977f 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -222,7 +222,7 @@ module Jekyll def where(input, property, value) return input unless input.is_a?(Enumerable) input = input.values if input.is_a?(Hash) - input.select { |object| item_property(object, property).to_s == value.to_s } + input.select { |object| Array(item_property(object, property)).map(&:to_s).include?(value.to_s) } end # Sort an array of objects diff --git a/test/test_filters.rb b/test/test_filters.rb index d8bce740..de59bc02 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -321,6 +321,21 @@ class TestFilters < JekyllUnitTest assert_equal 2, @filter.where(@array_of_objects, "color", "red").length end + should "filter array properties appropriately" do + hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>["x"]}, "c"=>{"tags"=>["y","z"]}} + assert_equal 2, @filter.where(hash, "tags", "x").length + end + + should "filter array properties alongside string properties" do + hash = {"a"=>{"tags"=>["x","y"]}, "b"=>{"tags"=>"x"}, "c"=>{"tags"=>["y","z"]}} + assert_equal 2, @filter.where(hash, "tags", "x").length + end + + should "not match substrings" do + hash = {"a"=>{"category"=>"bear"}, "b"=>{"category"=>"wolf"}, "c"=>{"category"=>["bear","lion"]}} + assert_equal 0, @filter.where(hash, "category", "ear").length + end + should "stringify during comparison for compatibility with liquid parsing" do hash = { "The Words" => {"rating" => 1.2, "featured" => false},