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