diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-09 11:28:15 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-01-09 11:28:15 -0800 |
commit | cf82e485d1511330c0607612c24712255739df49 (patch) | |
tree | 1313b052aaabb9824016390d5ac5bbfd6b285e8a | |
parent | 4f403bc0f1176e56854f4d994bf622dafaec5ea0 (diff) | |
download | psych-cf82e485d1511330c0607612c24712255739df49.zip |
* 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
-rw-r--r-- | CHANGELOG.rdoc | 9 | ||||
-rw-r--r-- | lib/psych/scalar_scanner.rb | 2 | ||||
-rw-r--r-- | test/psych/test_numeric.rb | 4 | ||||
-rw-r--r-- | test/psych/test_string.rb | 4 |
4 files changed, 18 insertions, 1 deletions
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 291ce97..98e3524 100644 --- a/CHANGELOG.rdoc +++ b/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 diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index d0beee3..5759459 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -96,7 +96,7 @@ module Psych @string_cache[string] = true string else - Float(string.gsub(/[,_]/, '')) + Float(string.gsub(/[,_]|\.$/, '')) end else int = parse_int string.gsub(/[,_]/, '') diff --git a/test/psych/test_numeric.rb b/test/psych/test_numeric.rb index 200a9f0..0858e79 100644 --- a/test/psych/test_numeric.rb +++ b/test/psych/test_numeric.rb @@ -16,6 +16,10 @@ module Psych $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 diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 0c5d4d2..aa6866b 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -102,6 +102,10 @@ module Psych 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| |