Closed pdehaan closed 2 years ago
I checked the behavior of shopify/liquid for these cases (except that they don't have a json filter). Here's some changes will be made on LiquidJS to align with Ruby:
join
, reverse
, truncatewords
wont throw on nil
input, LiquidJS will not throw as wellconcat
, sort
, sort_natural
will ignore nil value input so undefined
will not be added into result array. Actually, toArray
will return []
for null/undefined
instead of [null]/[undefined]
split
will return empty array for nil input and remove trailing empty stringsAwesome, thanks… Here's the current results for 9.35.1 (where foo
is undefined
):
FILTER | VALUE | +JSON FILTER | VALUE |
---|---|---|---|
{{ foo \| abs }} |
NaN |
{{ foo \| abs \| json }} |
null |
{{ foo \| append: bar }} |
{{ foo \| append: bar \| json }} |
"" | |
{{ foo \| capitalize }} |
{{ foo \| capitalize \| json }} |
"" | |
{{ foo \| ceil }} |
NaN |
{{ foo \| ceil \| json }} |
null |
{{ foo \| concat }} |
{{ foo \| concat \| json }} |
[null] |
|
{{ foo \| date }} |
{{ foo \| date \| json }} |
||
{{ foo \| divided_by }} |
NaN |
{{ foo \| divided_by \| json }} |
null |
{{ foo \| downcase }} |
{{ foo \| downcase \| json }} |
"" | |
{{ foo \| escape }} |
{{ foo \| escape \| json }} |
"" | |
{{ foo \| escape_once }} |
{{ foo \| escape_once \| json }} |
"" | |
{{ foo \| first }} |
{{ foo \| first \| json }} |
"" | |
{{ foo \| floor }} |
NaN |
{{ foo \| floor \| json }} |
null |
{{ foo \| join }} |
{{ foo \| join \| json }} |
"" | |
{{ foo \| json }} |
{{ foo \| json }} |
||
{{ foo \| last }} |
{{ foo \| last \| json }} |
"" | |
{{ foo \| lstrip }} |
{{ foo \| lstrip \| json }} |
"" | |
{{ foo \| map }} |
{{ foo \| map \| json }} |
[] |
|
{{ foo \| minus }} |
NaN |
{{ foo \| minus \| json }} |
null |
{{ foo \| modulo }} |
NaN |
{{ foo \| modulo \| json }} |
null |
{{ foo \| newline_to_br }} |
{{ foo \| newline_to_br \| json }} |
"" | |
{{ foo \| plus }} |
NaN |
{{ foo \| plus \| json }} |
null |
{{ foo \| prepend: bar }} |
{{ foo \| prepend: bar \| json }} |
"" | |
{{ foo \| remove }} |
{{ foo \| remove \| json }} |
"" | |
{{ foo \| remove_first }} |
{{ foo \| remove_first \| json }} |
"" | |
{{ foo \| replace }} |
{{ foo \| replace \| json }} |
"" | |
{{ foo \| replace_first }} |
{{ foo \| replace_first \| json }} |
"" | |
{{ foo \| reverse }} |
{{ foo \| reverse \| json }} |
[] |
|
{{ foo \| round }} |
NaN |
{{ foo \| round \| json }} |
null |
{{ foo \| rstrip }} |
{{ foo \| rstrip \| json }} |
"" | |
{{ foo \| slice }} |
{{ foo \| slice \| json }} |
[] |
|
{{ foo \| sort }} |
{{ foo \| sort \| json }} |
[] |
|
{{ foo \| sort_natural }} |
{{ foo \| sort_natural \| json }} |
[] |
|
{{ foo \| split }} |
{{ foo \| split \| json }} |
[] |
|
{{ foo \| strip }} |
{{ foo \| strip \| json }} |
"" | |
{{ foo \| strip_html }} |
{{ foo \| strip_html \| json }} |
"" | |
{{ foo \| strip_newlines }} |
{{ foo \| strip_newlines \| json }} |
"" | |
{{ foo \| times }} |
NaN |
{{ foo \| times \| json }} |
null |
{{ foo \| truncate }} |
{{ foo \| truncate \| json }} |
"" | |
{{ foo \| truncatewords }} |
{{ foo \| truncatewords \| json }} |
"" | |
{{ foo \| uniq }} |
{{ foo \| uniq \| json }} |
[] |
|
{{ foo \| upcase }} |
{{ foo \| upcase \| json }} |
"" | |
{{ foo \| url_decode }} |
{{ foo \| url_decode \| json }} |
"" | |
{{ foo \| url_encode }} |
{{ foo \| url_encode \| json }} |
"" | |
{{ foo \| where }} |
{{ foo \| where \| json }} |
[] |
Looks like the only curious entry in 9.35.1 is {{ undefined | concat }}
which returns [null]
:
<p>{{ foo | concat | size }} === 1</p>
<p>{{ foo | concat | json }} === [null]</p>
Related to #479 liquidjs@9.35.0
Apologies for the bad code:
OUTPUT
Interestingly it looks like
{{ undefined | escape_once }}
returns the literal string "undefined". Otherwise nothing too suspicious looking here (all the math functions seems to return NaN, which is semi-expected).If I append the
| json
filter to each test case, it gets more interesting:It looks like the
NaN
now converts tonull
(presumablyNaN
isn't valid JSON). Interesting cases might be: