Skip to content
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

Test array filters added in Shopify/Liquid v5.7.2 #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jg-rp
Copy link
Owner

@jg-rp jg-rp commented Feb 11, 2025

This PR adds test cases for the following filters as they appear in version 5.7.2 of Shopify/Liquid.

  • reject
  • has
  • find
  • find_index

Note that these filters do not currently support arguments for testing/selecting child properties at arbitrary depths. See Shopify/liquid#1906.

Observations

Some observations that hold true for all array filters (as of v5.7.2).

  • The second argument, target_value, is optional and it does not need to be a string, contrary to what the doc comments say.
  • Explicitly testing for null/nil/None is not supported. For example, a | has: 'foo' , a | has: 'foo', nil and a | has: 'foo', nosuchthing are equivalent. Shopify/Liquid does not distinguish between the default of nil and an explicit nil/null.
  • Inputs are intended to be arrays of objects/hashes. If the input is an object/hash or primitive value, it gets coerced to a single element array with the input value being the only item.
  • In Ruby, subscripting a string with another string will return a substring if the first string contains the second. This leads to {{ 'foo' | has: 'oo' }} and {{ 'foo,bar' | split: ',' | has: 'oo' }} being true, and some odd results when filtering arrays of string values, {{ 'x,y,cat' | split: ',' | reject: 'c' | join: ', ' }}. Shopify/Liquid does include tests covering this behaviour.
  • If the input array contains a nil/null/None before a successful match, the result is nil/null/None. {{ a | has: 'z' }} renders nothing when a is equal to ["x", nil, "z"]. This was the case with the where filter before version 5.7.
  • An exception is raised if the input array contains an integer and target_value is a string.

See also harttle/liquidjs#799

@jg-rp jg-rp marked this pull request as ready for review February 13, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant