diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-12-10 21:31:02 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-12-10 21:31:30 +0900 |
| commit | bf431e77b8851e87f1a65ad3bf20d7e035b31472 (patch) | |
| tree | e4ba019202bb26a8abc226438940072fc2c3322c /src/string.c | |
| parent | 543a9f84d11c2c0e96de52bd2e936467f13d26e8 (diff) | |
| download | mruby-bf431e77b8851e87f1a65ad3bf20d7e035b31472.tar.gz mruby-bf431e77b8851e87f1a65ad3bf20d7e035b31472.zip | |
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
```
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/string.c b/src/string.c index f75679513..f4fb46e5a 100644 --- a/src/string.c +++ b/src/string.c @@ -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); } |
