From 31ba0921f8fe342ce317b1c9638b23756bffc9ff Mon Sep 17 00:00:00 2001 From: Tomer Brisker Date: Sat, 8 Aug 2020 14:46:05 +0300 Subject: [ruby/psych] Improve float scalar scanner Previously, `+.inf` was not handled correctly. Additionally, the regexp was checking for inf and NaN, even though these cases are handled earlier in the condition. Added a few tests to ensure handling some missing cases. https://github.com/ruby/psych/commit/6e0e7a1e9f --- ext/psych/lib/psych/scalar_scanner.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'ext/psych') diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb index d565a336e8..01f7a2ef1c 100644 --- a/ext/psych/lib/psych/scalar_scanner.rb +++ b/ext/psych/lib/psych/scalar_scanner.rb @@ -9,9 +9,8 @@ module Psych TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/ # Taken from http://yaml.org/type/float.html - FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10) - |[-+]?\.(inf|Inf|INF)(?# infinity) - |\.(nan|NaN|NAN)(?# not a number))$/x + # Base 60, [-+]inf and NaN are handled separately + FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10))$/x # Taken from http://yaml.org/type/int.html INTEGER = /^(?:[-+]?0b[0-1_,]+ (?# base 2) @@ -61,7 +60,7 @@ module Psych rescue ArgumentError string end - elsif string.match?(/^\.inf$/i) + elsif string.match?(/^\+?\.inf$/i) Float::INFINITY elsif string.match?(/^-\.inf$/i) -Float::INFINITY -- cgit v1.2.3