Skip to content

Commit

Permalink
Merge pull request #1760 from mtasaka/nil-nil-comparison-fix
Browse files Browse the repository at this point in the history
change: make nil_safe_casecmp judge compatible for nil-nil comparison
  • Loading branch information
ianks committed Mar 21, 2024
2 parents 4a4fe3c + 4924822 commit dba7330
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/liquid/standardfilters.rb
Expand Up @@ -944,6 +944,8 @@ def nil_safe_compare(a, b)
def nil_safe_casecmp(a, b)
if !a.nil? && !b.nil?
a.to_s.casecmp(b.to_s)
elsif a.nil? && b.nil?
0
else
a.nil? ? 1 : -1
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/standard_filter_test.rb
Expand Up @@ -331,8 +331,8 @@ def test_sort_natural_when_property_is_sometimes_missing_puts_nils_last
{ "price" => "1", "handle" => "gamma" },
{ "price" => 2, "handle" => "epsilon" },
{ "price" => "4", "handle" => "alpha" },
{ "handle" => "delta" },
{ "handle" => "beta" },
{ "handle" => "delta" },
]
assert_equal(expectation, @filters.sort_natural(input, "price"))
end
Expand Down

0 comments on commit dba7330

Please sign in to comment.