diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-12-11 16:40:39 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-12-11 16:40:39 +0900 |
| commit | 7192429e83b3931928d163fc32bf704d513a9f72 (patch) | |
| tree | ebb43bdd2763ef2c744fab6d1db251e64f01e84e /src/string.c | |
| parent | 994da0fd7375b2ef0fb618db66ffeeac8fd9b383 (diff) | |
| download | mruby-7192429e83b3931928d163fc32bf704d513a9f72.tar.gz mruby-7192429e83b3931928d163fc32bf704d513a9f72.zip | |
Fix behavior of `Kernel#Integer` to numbers ending with `_` and spaces
#### Before this patch:
```ruby
Integer("1_ ") #=> 1
```
#### After this patch (same as Ruby):
```ruby
Integer("1_ ") #=> ArgumentError
```
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c index f4fb46e5a..5a0a6a233 100644 --- a/src/string.c +++ b/src/string.c @@ -2393,9 +2393,10 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, } val = (mrb_int)n; if (badcheck) { - if (p == str) goto bad; /* no number */ + if (p == str) goto bad; /* no number */ + if (*(p - 1) == '_') goto bad; /* trailing '_' */ while (p<pend && ISSPACE(*p)) p++; - if (p<pend) goto bad; /* trailing garbage */ + if (p<pend) goto bad; /* trailing garbage */ } return mrb_fixnum_value(sign ? val : -val); |
