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

ruby-changes:26703

From: tenderlove <ko1@a...>
Date: Thu, 10 Jan 2013 04:26:55 +0900 (JST)
Subject: [ruby-changes:26703] tenderlove:r38754 (trunk): * ext/psych/lib/psych/scalar_scanner.rb: strip trailing dots from

tenderlove	2013-01-10 04:26:45 +0900 (Thu, 10 Jan 2013)

  New Revision: 38754

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38754

  Log:
    * ext/psych/lib/psych/scalar_scanner.rb: strip trailing dots from
      floats so that Float() will not raise an exception.
    
    * test/psych/test_numeric.rb: test to ensure "1." can be loaded
    
    * test/psych/test_string.rb: make sure "1." can round trip

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/scalar_scanner.rb
    trunk/test/psych/test_numeric.rb
    trunk/test/psych/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38753)
+++ ChangeLog	(revision 38754)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 10 04:23:07 2013  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/scalar_scanner.rb: strip trailing dots from
+	  floats so that Float() will not raise an exception.
+
+	* test/psych/test_numeric.rb: test to ensure "1." can be loaded
+
+	* test/psych/test_string.rb: make sure "1." can round trip
+
 Thu Jan 10 03:38:40 2013  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/yaml_tree.rb: ascii only binary strings
Index: ext/psych/lib/psych/scalar_scanner.rb
===================================================================
--- ext/psych/lib/psych/scalar_scanner.rb	(revision 38753)
+++ ext/psych/lib/psych/scalar_scanner.rb	(revision 38754)
@@ -96,7 +96,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/scalar_scanner.rb#L96
           @string_cache[string] = true
           string
         else
-          Float(string.gsub(/[,_]/, ''))
+          Float(string.gsub(/[,_]|\.$/, ''))
         end
       else
         int = parse_int string.gsub(/[,_]/, '')
Index: test/psych/test_numeric.rb
===================================================================
--- test/psych/test_numeric.rb	(revision 38753)
+++ test/psych/test_numeric.rb	(revision 38754)
@@ -16,6 +16,10 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_numeric.rb#L16
       $DEBUG = @old_debug
     end
 
+    def test_load_float_with_dot
+      assert_equal 1.0, Psych.load('--- 1.')
+    end
+
     def test_non_float_with_0
       str = Psych.load('--- 090')
       assert_equal '090', str
Index: test/psych/test_string.rb
===================================================================
--- test/psych/test_string.rb	(revision 38753)
+++ test/psych/test_string.rb	(revision 38754)
@@ -102,6 +102,10 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_string.rb#L102
       assert_cycle string
     end
 
+    def test_float_confusion
+      assert_cycle '1.'
+    end
+
     def binary_string percentage = 0.31, length = 100
       string = ''
       (percentage * length).to_i.times do |i|

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

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