From bf431e77b8851e87f1a65ad3bf20d7e035b31472 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 10 Dec 2019 21:31:02 +0900 Subject: 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 ``` --- src/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/string.c') 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); } -- cgit v1.2.3