Project

General

Profile

Bug #6312 ยป 0001-make-psych-less-noisy-by-checking-if-a-value-is-a-va.patch

riffraff (gabriele renzi), 04/18/2012 01:26 AM

View differences:

ext/psych/lib/psych/scalar_scanner.rb
|[-+]?\.(inf|Inf|INF)(?# infinity)
|\.(nan|NaN|NAN)(?# not a number))$/x
# Taken from http://yaml.org/type/int.html but accepts "," as a separator
# as this is the current psych behaviour
INT = /^(?:
[-+]?0b[0-1_,]+ # base 2
|[-+]?0[0-7_,]+ # base 8
|[-+]? (?: 0|[1-9][0-9_,]* ) # base 10
|[-+]?0x[0-9a-fA-F_,]+ # base 16
|[-+]?[1-9][0-9_,]* (?: :[0-5]?[0-9] )+ # base 60
)$/x
# Create a new scanner
def initialize
@string_cache = {}
......
end
i
when FLOAT
if string.count('.') < 2
begin
return Float(string.gsub(/[,_]/, ''))
rescue ArgumentError
end
end
@string_cache[string] = true
string
when INT
begin
return Float(string.gsub(/[,_]/, ''))
return Integer(string.gsub(/[,_]/, ''))
rescue ArgumentError
end
@string_cache[string] = true
string
else
if string.count('.') < 2
begin
return Integer(string.gsub(/[,_]/, ''))
rescue ArgumentError
end
end
@string_cache[string] = true
string
test/psych/test_numeric.rb
# http://yaml.org/type/float.html
# http://yaml.org/type/int.html
class TestNumeric < TestCase
def setup
@old_debug = $DEBUG
$DEBUG = true
end
def teardown
$DEBUG = @old_debug
end
def test_non_float_with_0
str = Psych.load('--- 090')
assert_equal '090', str
......
decimal = BigDecimal("12.34")
assert_cycle decimal
end
def test_does_not_attempt_numeric
str = Psych.load('--- 4 roses')
assert_equal '4 roses', str
str = Psych.load('--- 1.1.1')
assert_equal '1.1.1', str
end
end
end
    (1-1/1)