diff options
-rw-r--r-- | lib/psych/scalar_scanner.rb | 5 | ||||
-rw-r--r-- | test/psych/test_scalar_scanner.rb | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index a849359..449efa4 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -10,7 +10,6 @@ module Psych # Taken from http://yaml.org/type/float.html FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10) - |[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60) |[-+]?\.(inf|Inf|INF)(?# infinity) |\.(nan|NaN|NAN)(?# not a number))$/x @@ -83,13 +82,13 @@ module Psych else @symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, '')) end - when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/ + when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/ i = 0 string.split(':').each_with_index do |n,e| i += (n.to_i * 60 ** (e - 2).abs) end i - when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/ + when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/ i = 0 string.split(':').each_with_index do |n,e| i += (n.to_f * 60 ** (e - 2).abs) diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb index 9b6d8c1..e51fc69 100644 --- a/test/psych/test_scalar_scanner.rb +++ b/test/psych/test_scalar_scanner.rb @@ -88,6 +88,12 @@ module Psych assert_equal :foo, ss.tokenize(':foo') end + def test_scan_not_sexagesimal + assert_equal '00:00:00:00:0f', ss.tokenize('00:00:00:00:0f') + assert_equal '00:00:00:00:00', ss.tokenize('00:00:00:00:00') + assert_equal '00:00:00:00:00.0', ss.tokenize('00:00:00:00:00.0') + end + def test_scan_sexagesimal_float assert_equal 685230.15, ss.tokenize('190:20:30.15') end |