Skip to content

Commit

Permalink
* ext/psych/lib/psych/scalar_scanner.rb: strip trailing dots from
Browse files Browse the repository at this point in the history
  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
tenderlove committed Jan 9, 2013
1 parent 4f403bc commit cf82e48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions 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
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/scalar_scanner.rb
Expand Up @@ -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(/[,_]/, '')
Expand Down
4 changes: 4 additions & 0 deletions test/psych/test_numeric.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/psych/test_string.rb
Expand Up @@ -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|
Expand Down

1 comment on commit cf82e48

@BanzaiMan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.