Skip to content
Browse files

* 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

fixes #109
  • Loading branch information...
1 parent 4f403bc commit cf82e485d1511330c0607612c24712255739df49 @tenderlove committed Jan 9, 2013
Showing with 18 additions and 1 deletion.
  1. +9 −0 CHANGELOG.rdoc
  2. +1 −1 lib/psych/scalar_scanner.rb
  3. +4 −0 test/psych/test_numeric.rb
  4. +4 −0 test/psych/test_string.rb
View
9 CHANGELOG.rdoc
@@ -1,3 +1,12 @@
+Thu Jan 10 04:23:07 2013 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * 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
+
Sat Nov 17 12:03:41 2012 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/scalar_scanner.rb: avoid raising exceptions when
View
2 lib/psych/scalar_scanner.rb
@@ -96,7 +96,7 @@ def tokenize string
@string_cache[string] = true
string
else
- Float(string.gsub(/[,_]/, ''))
+ Float(string.gsub(/[,_]|\.$/, ''))
end
else
int = parse_int string.gsub(/[,_]/, '')
View
4 test/psych/test_numeric.rb
@@ -16,6 +16,10 @@ def teardown
$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
View
4 test/psych/test_string.rb
@@ -102,6 +102,10 @@ def test_binary
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|

1 comment on commit cf82e48

@BanzaiMan

@tenderlove Is there a plan for a release containing this fix?

Please sign in to comment.
Something went wrong with that request. Please try again.