mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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!!!
b48f3afa3b
This commit is contained in:
parent
643344dc94
commit
39f275edf7
2 changed files with 35 additions and 35 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue