Fix behavior of String#to_i/Kernel#Integer to numbers starting with _

#### Before this patch:

  ```ruby
  Integer("_1")  #=> 1
  "_1".to_i      #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("_1")  #=> ArgumentError
  "_1".to_i      #=> 0
  ```
This commit is contained in:
KOBAYASHI Shuji
2019-12-10 21:31:02 +09:00
parent 543a9f84d1
commit bf431e77b8
3 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -2354,7 +2354,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base,
if (*(p - 1) == '0')
p--;
}
if (p == pend) {
if (p == pend || *p == '_') {
if (badcheck) goto bad;
return mrb_fixnum_value(0);
}