diff options
author | Cody Cutrer <cody@instructure.com> | 2016-03-29 13:47:35 -0600 |
---|---|---|
committer | Cody Cutrer <cody@instructure.com> | 2016-03-29 14:10:50 -0600 |
commit | d5c9b2d4aee89483b79dc4930b79dec7031ef936 (patch) | |
tree | ac3db21f765508d41aaf09faec36813d73745f3c | |
parent | c14a05c0f15422e7e524d41d9da1b859e6a4dc69 (diff) | |
download | psych-d5c9b2d4aee89483b79dc4930b79dec7031ef936.zip |
fix serialization of a string that looks like a valid YAML float
refs gh-156
(but isn't a valid ruby float)
-rw-r--r-- | lib/psych/scalar_scanner.rb | 2 | ||||
-rw-r--r-- | test/psych/test_scalar_scanner.rb | 4 | ||||
-rw-r--r-- | test/psych/test_string.rb | 4 |
3 files changed, 9 insertions, 1 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index f519da1..a849359 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -100,7 +100,7 @@ module Psych @string_cache[string] = true string else - Float(string.gsub(/[,_]|\.$/, '')) + Float(string.gsub(/[,_]|\.([Ee]|$)/, '\1')) end else int = parse_int string.gsub(/[,_]/, '') diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index 7ad18c5..2599989 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -74,6 +74,10 @@ module Psych assert ss.tokenize('.nan').nan? end + def test_scan_float_with_exponent_but_no_fraction + assert_equal(0.0, ss.tokenize('0.E+0')) + end + def test_scan_null assert_equal nil, ss.tokenize('null') assert_equal nil, ss.tokenize('~') diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 51aef40..25c6353 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -99,6 +99,10 @@ module Psych assert_cycle '+.' end + def test_float_with_no_fractional_before_exponent + assert_cycle '0.E+0' + end + def test_string_subclass_with_anchor y = Psych.load <<-eoyml --- |