You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.5 KiB
35 lines
1.5 KiB
8 years ago
|
From b3d811781ec24e5bc3710c62cedac472b7999082 Mon Sep 17 00:00:00 2001
|
||
|
From: Akira Matsuda <ronnie@dio.jp>
|
||
|
Date: Mon, 12 Dec 2016 23:41:59 +0900
|
||
|
Subject: [PATCH] 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(-)
|
||
|
|
||
|
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
|
||
|
index 1812de0..5275c0e 100644
|
||
|
--- a/activesupport/lib/active_support/xml_mini.rb
|
||
|
+++ b/activesupport/lib/active_support/xml_mini.rb
|
||
|
@@ -68,7 +68,17 @@ def content_type
|
||
|
"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 },
|