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:
KOBAYASHI Shuji
2019-12-11 16:40:39 +09:00
parent 994da0fd73
commit 7192429e83
3 changed files with 7 additions and 2 deletions
+3 -2
View File
@@ -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);