diff options
author | Kouhei Sutou <kou@clear-code.com> | 2019-05-25 18:25:37 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-08-04 11:55:49 +0900 |
commit | 39f275edf7284ef0c0f9b9391038ae9f2c019731 (patch) | |
tree | e50ea0a7d6ef28453b79ddfd728570be7aa4b07d /lib | |
parent | 643344dc9460626617c9ce88f07b3ae0fed49150 (diff) | |
download | ruby-39f275edf7284ef0c0f9b9391038ae9f2c019731.tar.gz |
[ruby/rexml] xpath number: fix a bug that false is converted to NaN
GitHub: fix #18
It must be 0.
Reported by Mirko Budszuhn. Thanks!!!
https://github.com/ruby/rexml/commit/b48f3afa3b
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rexml/functions.rb | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb index a0f4823ada..77926bf2af 100644 --- a/lib/rexml/functions.rb +++ b/lib/rexml/functions.rb @@ -66,7 +66,6 @@ module REXML def Functions::id( object ) end - # UNTESTED def Functions::local_name(node_set=nil) get_namespace(node_set) do |node| return node.local_name @@ -386,25 +385,23 @@ module REXML # # an object of a type other than the four basic types is converted to a # number in a way that is dependent on that type - def Functions::number( object=nil ) - object = @@context[:node] unless object + def Functions::number(object=@@context[:node]) case object when true Float(1) when false Float(0) when Array - number(string( object )) + number(string(object)) when Numeric object.to_f else - str = string( object ) - # If XPath ever gets scientific notation... - #if str =~ /^\s*-?(\d*\.?\d+|\d+\.)([Ee]\d*)?\s*$/ - if str =~ /^\s*-?(\d*\.?\d+|\d+\.)\s*$/ - str.to_f + str = string(object) + case str.strip + when /\A\s*(-?(?:\d+(?:\.\d*)?|\.\d+))\s*\z/ + $1.to_f else - (0.0 / 0.0) + Float::NAN end end end |