From 7192429e83b3931928d163fc32bf704d513a9f72 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Wed, 11 Dec 2019 16:40:39 +0900 Subject: 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 ``` --- src/string.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/string.c') 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