summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-12-09 21:47:59 +0900
committerKOBAYASHI Shuji <[email protected]>2019-12-09 21:47:59 +0900
commit0893ee492c189e4d2c5badfd326a2e45049c89a5 (patch)
tree94a9d96b616d91deb2876ef3b9c9e84eb35a613e /src/string.c
parent8267993988971a7797cdc8a5c6d161f3355f1af2 (diff)
downloadmruby-0893ee492c189e4d2c5badfd326a2e45049c89a5.tar.gz
mruby-0893ee492c189e4d2c5badfd326a2e45049c89a5.zip
Fix that `String#to_f` accepts consecutive `_` as a numeric expression
Consecutive `_` is not allowed as a numeric expression: 1_2__3 #=> SyntaxError Float("1_2__3") #=> ArgumentError Integer("1_2__3") #=> ArgumentError "1_2__3".to_i #=> 12 But `String#to_f` accept it, so I fixed the issue. Before this patch: "1_2__3".to_f #=> 123 After this patch: "1_2__3".to_f #=> 12
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/string.c b/src/string.c
index 61fbd4ded..f75679513 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2522,15 +2522,10 @@ bad:
while (p < end && n < e) prev = *n++ = *p++;
while (*p) {
if (*p == '_') {
- /* remove underscores between digits */
- if (badcheck) {
- if (n == buf || !ISDIGIT(prev)) goto bad;
- ++p;
- if (!ISDIGIT(*p)) goto bad;
- }
- else {
- while (*++p == '_');
- continue;
+ /* remove an underscore between digits */
+ if (n == buf || !ISDIGIT(prev) || (++p, !ISDIGIT(*p))) {
+ if (badcheck) goto bad;
+ break;
}
}
prev = *p++;