New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt accessing only valid item properties #6992
Conversation
does this need tests with it? |
d157505
to
4c9fbcb
Compare
Looks like we need a test for what happens if something isn't an array, at least. |
@mattr- Since the time the latest update to |
I'm not ready to introduce the complexity for a |
test/test_filters.rb
Outdated
@@ -849,6 +849,20 @@ def to_liquid | |||
assert_equal 2, @filter.where(array, "color", nil).length | |||
end | |||
|
|||
should "filter array and string objects appropriately" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this test, the functionality feels too complicated to fix the bug. The most straightforward way I know to test this is to write something like:
should "not throw exception when an item doesn't have the property" do
array = [{}, { "color" => nil }, { "color" => "" }, { "color" => "text" }, { "foo" => "bar" }]
assert_equal [{ "color" => "text" }], @filter.where(hash, "color", "text")
end
Also, filtering on sub properties, as in #6939 (context.type
), isn't valid syntax. This feels like we need a better reproduction case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your test-case passes on master
. The issue outlined in #6939 is actually due to #item_property
encountering a nil
element.
Modifying your test-case to the following (will fail on current master
:
should "not throw exception when an item doesn't have the property" do
array = [{}, { "color" => "text" }, { "foo" => "bar" }, nil]
assert_equal [{ "color" => "text" }], @filter.where(array, "color", "text")
end
Another case that'll fail on master
:
should "not throw exception when an item doesn't have the property" do
array = [{}, { "color" => "text" }, [], { "foo" => "bar" }]
assert_equal [{ "color" => "text" }], @filter.where(array, "color", "text")
end
Resolves #6939