Project

General

Profile

Actions

Bug #13880

closed

`BigDecimal(string)` should raise on invalid values in `string`

Bug #13880: `BigDecimal(string)` should raise on invalid values in `string`

Added by ojab (ojab ojab) about 8 years ago. Updated almost 7 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[ruby-core:82704]

Description

Right now BigDecimal() behaviour differs from Integer() and Float():

2.4.1 :001 > require 'bigdecimal' => true 2.4.1 :002 > BigDecimal('1,') => 0.1e1 2.4.1 :003 > Integer('1,') ArgumentError: invalid value for Integer(): "1," from (irb):3:in `Integer' from (irb):3 from /home/ojab/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>' 2.4.1 :004 > Float('1,') ArgumentError: invalid value for Float(): "1," from (irb):4:in `Float' from (irb):4 from /home/ojab/.rvm/rubies/ruby-2.4.1/bin/irb:11:in `<main>' 

and right now AFAIU there is no way to convert, for example, String to BigDecimal with validation.

I think that BigDecimal() should likewise raise for consistency, 'bigdecimal/util' & .to_d can be used for conversion without checks analogous to .to_f/.to_i/etc.

Updated by ojab (ojab ojab) about 8 years ago Actions #1

  • ruby -v set to ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

Updated by ojab (ojab ojab) about 8 years ago Actions #2

  • Description updated (diff)

Updated by mrkn (Kenta Murata) almost 8 years ago Actions #3 [ruby-core:84235]

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)

Updated by mrkn (Kenta Murata) almost 8 years ago Actions #5

  • Target version set to 2.6

Updated by naruse (Yui NARUSE) almost 8 years ago Actions #6

  • Target version deleted (2.6)

Updated by mrkn (Kenta Murata) almost 7 years ago Actions #7 [ruby-core:90353]

  • Status changed from Assigned to Closed

Fixed in r66222

Actions

Also available in: PDF Atom