mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Merge pull request #735 from Shopify/fix-to-number-for-negative-float-strings
Fix to_number filter for negative float strings
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ module Liquid
|
|||||||
when Numeric
|
when Numeric
|
||||||
obj
|
obj
|
||||||
when String
|
when String
|
||||||
(obj.strip =~ /\A\d+\.\d+\z/) ? BigDecimal.new(obj) : obj.to_i
|
(obj.strip =~ /\A-?\d+\.\d+\z/) ? BigDecimal.new(obj) : obj.to_i
|
||||||
else
|
else
|
||||||
if obj.respond_to?(:to_number)
|
if obj.respond_to?(:to_number)
|
||||||
obj.to_number
|
obj.to_number
|
||||||
|
|||||||
@@ -388,11 +388,10 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
def test_times
|
def test_times
|
||||||
assert_template_result "12", "{{ 3 | times:4 }}"
|
assert_template_result "12", "{{ 3 | times:4 }}"
|
||||||
assert_template_result "0", "{{ 'foo' | times:4 }}"
|
assert_template_result "0", "{{ 'foo' | times:4 }}"
|
||||||
|
|
||||||
assert_template_result "6", "{{ '2.1' | times:3 | replace: '.','-' | plus:0}}"
|
assert_template_result "6", "{{ '2.1' | times:3 | replace: '.','-' | plus:0}}"
|
||||||
|
|
||||||
assert_template_result "7.25", "{{ 0.0725 | times:100 }}"
|
assert_template_result "7.25", "{{ 0.0725 | times:100 }}"
|
||||||
|
assert_template_result "-7.25", '{{ "-0.0725" | times:100 }}'
|
||||||
|
assert_template_result "7.25", '{{ "-0.0725" | times: -100 }}'
|
||||||
assert_template_result "4", "{{ price | times:2 }}", 'price' => NumberLikeThing.new(2)
|
assert_template_result "4", "{{ price | times:2 }}", 'price' => NumberLikeThing.new(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user