mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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
```
This commit is contained in:
+3
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user