From b87619f94550ad37a5a4825b0c2c1acdb96b5f6e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 12 Dec 2016 23:41:59 +0900 Subject: Keep AS::XmlMini::PARSING["decimal"].call('') returning 0 BigDecimal('an invalid string') has changed its behavior to raise an ArgumentError since 1.3.0 https://bugs.ruby-lang.org/issues/10286 --- activesupport/lib/active_support/xml_mini.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/xml_mini.rb') diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index e16581d697..e3203ef076 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -68,7 +68,17 @@ module ActiveSupport "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc }, "integer" => Proc.new { |integer| integer.to_i }, "float" => Proc.new { |float| float.to_f }, - "decimal" => Proc.new { |number| BigDecimal(number) }, + "decimal" => Proc.new do |number| + if String === number + begin + BigDecimal(number) + rescue ArgumentError + BigDecimal('0') + end + else + BigDecimal(number) + end + end, "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, -- cgit v1.2.3