aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/xml_mini.rb
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2016-12-12 23:41:59 +0900
committerAkira Matsuda <ronnie@dio.jp>2016-12-13 00:06:08 +0900
commitb87619f94550ad37a5a4825b0c2c1acdb96b5f6e (patch)
tree35bdc24a15a06d40e6573595d08cc69dd730579f /activesupport/lib/active_support/xml_mini.rb
parent414484f68dcace66d0a9fcec3c22db5847b12b42 (diff)
downloadrails-b87619f94550ad37a5a4825b0c2c1acdb96b5f6e.tar.gz
rails-b87619f94550ad37a5a4825b0c2c1acdb96b5f6e.tar.bz2
rails-b87619f94550ad37a5a4825b0c2c1acdb96b5f6e.zip
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
Diffstat (limited to 'activesupport/lib/active_support/xml_mini.rb')
-rw-r--r--activesupport/lib/active_support/xml_mini.rb12
1 files changed, 11 insertions, 1 deletions
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 },