summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authorTomer Brisker <tbrisker@gmail.com>2020-08-08 14:46:05 +0300
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-08-31 19:34:06 +0900
commit31ba0921f8fe342ce317b1c9638b23756bffc9ff (patch)
tree37007f054f571c0bf912e91e09400b2c1f0dd347 /ext/psych
parentd19af1675c9dcf4ccef643e831d83976f1831101 (diff)
[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
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych/scalar_scanner.rb7
1 files changed, 3 insertions, 4 deletions
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