diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-15 08:15:32 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-15 08:15:32 +0000 |
commit | 0b1f6aed9414a4d7714910e61db08fdb2ac3ecd1 (patch) | |
tree | e11cbc65cf3da0f728bb02c481fb620056ccd192 /object.c | |
parent | 8c661ba264e642343d5097e7acd51e783f1d0337 (diff) | |
download | ruby-0b1f6aed9414a4d7714910e61db08fdb2ac3ecd1.tar.gz |
object.c: make String#to_f consistent with literal
* object.c (rb_cstr_to_dbl): stop at successive underscores, as
well as Float literals. [ruby-core:80098] [Bug #13105]
* `_` should be within digits
* only one `_` allowed between digits
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -2870,15 +2870,10 @@ rb_cstr_to_dbl(const char *p, int badcheck) 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++; |