change: make nil_safe_casecmp judge compatible for nil-nil comparison

Ruby returns 0 (not nil) for nil <=> nil, i.e. nil and nil are judged
as equal for comparison, and so returns nil_safe_compare .
ref: https://github.com/Shopify/liquid/pull/1476

To make the behavior of nil_safe_casecmp consistent with
nil_safe_compare , change nil_safe_casecmp so that comparison between
nil <=> nil return 0 (equal).

Also change testsuite to reflect this change.

Fixes #1759 .
This commit is contained in:
Mamoru TASAKA
2023-12-15 15:09:57 +09:00
parent c658bf970a
commit 4924822c88
2 changed files with 3 additions and 1 deletions
+2
View File
@@ -944,6 +944,8 @@ module Liquid
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