mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user