[前][次][番号順一覧][スレッド一覧]

ruby-changes:48147

From: nobu <ko1@a...>
Date: Sat, 21 Oct 2017 21:34:18 +0900 (JST)
Subject: [ruby-changes:48147] nobu:r60261 (trunk): Fix bug about String#scanf("%a")

nobu	2017-10-21 21:34:13 +0900 (Sat, 21 Oct 2017)

  New Revision: 60261

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60261

  Log:
    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@y...>

  Modified files:
    trunk/lib/scanf.rb
    trunk/test/scanf/test_scanf.rb
Index: test/scanf/test_scanf.rb
===================================================================
--- test/scanf/test_scanf.rb	(revision 60260)
+++ test/scanf/test_scanf.rb	(revision 60261)
@@ -258,6 +258,7 @@ module ScanfTests https://github.com/ruby/ruby/blob/trunk/test/scanf/test_scanf.rb#L258
       [ "%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
Index: lib/scanf.rb
===================================================================
--- lib/scanf.rb	(revision 60260)
+++ lib/scanf.rb	(revision 60261)
@@ -295,7 +295,7 @@ module Scanf https://github.com/ruby/ruby/blob/trunk/lib/scanf.rb#L295
 
     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 https://github.com/ruby/ruby/blob/trunk/lib/scanf.rb#L411
 
           # %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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]