mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Merge pull request #1783 from Shopify/contains-encoding
Fallback to binary comparison when `contains` RHS is UTF8 encoded
This commit is contained in:
@@ -24,6 +24,9 @@ module Liquid
|
|||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
rescue Encoding::CompatibilityError
|
||||||
|
# "✅".b.include?("✅") raises Encoding::CompatibilityError despite being materially equal
|
||||||
|
left.b.include?(right.b)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
assert_evaluates_false('bob', 'contains', '---')
|
assert_evaluates_false('bob', 'contains', '---')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_contains_binary_encoding_compatibility_with_utf8
|
||||||
|
assert_evaluates_true('🙈'.b, 'contains', '🙈')
|
||||||
|
assert_evaluates_true('🙈', 'contains', '🙈'.b)
|
||||||
|
end
|
||||||
|
|
||||||
def test_invalid_comparation_operator
|
def test_invalid_comparation_operator
|
||||||
assert_evaluates_argument_error(1, '~~', 0)
|
assert_evaluates_argument_error(1, '~~', 0)
|
||||||
end
|
end
|
||||||
@@ -166,14 +171,14 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
def assert_evaluates_true(left, op, right)
|
def assert_evaluates_true(left, op, right)
|
||||||
assert(
|
assert(
|
||||||
Condition.new(left, op, right).evaluate(@context),
|
Condition.new(left, op, right).evaluate(@context),
|
||||||
"Evaluated false: #{left} #{op} #{right}",
|
"Evaluated false: #{left.inspect} #{op} #{right.inspect}",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_evaluates_false(left, op, right)
|
def assert_evaluates_false(left, op, right)
|
||||||
assert(
|
assert(
|
||||||
!Condition.new(left, op, right).evaluate(@context),
|
!Condition.new(left, op, right).evaluate(@context),
|
||||||
"Evaluated true: #{left} #{op} #{right}",
|
"Evaluated true: #{left.inspect} #{op} #{right.inspect}",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user