mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix bug about String#scanf("%a")
* lib/scanf.rb (extract_float, initialize): allow to omit a sign on the binary exponent. [ruby-core:82435] [Bug #13833] [Fix GH-1689] From: tarotaro0 <tarousann11922960@yahoo.co.jp> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6fba455acb
commit
4bf6a04f49
2 changed files with 4 additions and 3 deletions
|
@ -295,7 +295,7 @@ module Scanf
|
|||
|
||||
def extract_float(s)
|
||||
return nil unless s &&! skip
|
||||
if /\A(?<sign>[-+]?)0[xX](?<frac>\.\h+|\h+(?:\.\h*)?)[pP](?<exp>[-+]\d+)/ =~ s
|
||||
if /\A(?<sign>[-+]?)0[xX](?<frac>\.\h+|\h+(?:\.\h*)?)[pP](?<exp>[-+]?\d+)/ =~ s
|
||||
f1, f2 = frac.split('.')
|
||||
f = f1.hex
|
||||
if f2
|
||||
|
@ -411,11 +411,11 @@ module Scanf
|
|||
|
||||
# %f
|
||||
when /%\*?[aefgAEFG]/
|
||||
[ '([-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))', :extract_float ]
|
||||
[ '([-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]?\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))', :extract_float ]
|
||||
|
||||
# %5f
|
||||
when /%\*?(\d+)[aefgAEFG]/
|
||||
[ '(?=[-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))' +
|
||||
[ '(?=[-+]?(?:0[xX](?:\.\h+|\h+(?:\.\h*)?)[pP][-+]?\d+|\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))' +
|
||||
"(\\S{1,#{$1}})", :extract_float ]
|
||||
|
||||
# %5s
|
||||
|
|
|
@ -258,6 +258,7 @@ module ScanfTests
|
|||
[ "%G", "+3.25e2", [325.0] ],
|
||||
[ "%f", "3.z", [3.0] ],
|
||||
[ "%a", "0X1P+10", [1024.0] ],
|
||||
[ "%a", "0X1P10", [1024.0] ],
|
||||
[ "%A", "0x1.deadbeefp+99", [1.1851510441583988e+30] ],
|
||||
|
||||
# Testing embedded matches including literal '[' behavior
|
||||
|
|
Loading…
Reference in a new issue