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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tenderlove committed Jan 9, 2013
1 parent ac8b186 commit b104e25
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Thu Jan 10 04:23:07 2013 Aaron Patterson <[email protected]>

* 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 <[email protected]>

* ext/psych/lib/psych/visitors/yaml_tree.rb: ascii only binary strings
Expand Down
2 changes: 1 addition & 1 deletion ext/psych/lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b104e25

Please sign in to comment.