Skip to content

Commit

Permalink
Merge pull request #438 from mthorn/master
Browse files Browse the repository at this point in the history
Fix ArgumentError with leading and trailing underscores in number str…
  • Loading branch information
tenderlove authored Jun 3, 2020
2 parents a8317a1 + ac2d2c9 commit 9f8c365
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def tokenize string
###
# Parse and return an int from +string+
def parse_int string
Integer(string.gsub(/[,]/, ''))
Integer(string.gsub(/[,_]/, ''))
end

###
Expand Down
3 changes: 3 additions & 0 deletions test/psych/test_scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_scan_int_commas_and_underscores
assert_equal 123_456_789, ss.tokenize('123_456_789')
assert_equal 123_456_789, ss.tokenize('123,456,789')
assert_equal 123_456_789, ss.tokenize('1_2,3,4_5,6_789')
assert_equal 123_456_789, ss.tokenize('1_2,3,4_5,6_789_')

assert_equal 0b010101010, ss.tokenize('0b010101010')
assert_equal 0b010101010, ss.tokenize('0b0,1_0,1_,0,1_01,0')
Expand All @@ -129,6 +130,8 @@ def test_scan_int_commas_and_underscores

assert_equal 0x123456789abcdef, ss.tokenize('0x123456789abcdef')
assert_equal 0x123456789abcdef, ss.tokenize('0x12_,34,_56,_789abcdef')
assert_equal 0x123456789abcdef, ss.tokenize('0x_12_,34,_56,_789abcdef')
assert_equal 0x123456789abcdef, ss.tokenize('0x12_,34,_56,_789abcdef__')
end
end
end

0 comments on commit 9f8c365

Please sign in to comment.