diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 7a92c6753..3b0ecf15d 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -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 diff --git a/test/integration/standard_filter_test.rb b/test/integration/standard_filter_test.rb index 28c006cb9..0564404c3 100644 --- a/test/integration/standard_filter_test.rb +++ b/test/integration/standard_filter_test.rb @@ -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