summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-21 06:39:43 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-21 06:39:43 +0000
commit6793c0a2270e4ec8ccc7450f66a3dc356e44f5b8 (patch)
tree8c1000de28607426e296ccec7428f101e9d48796 /lib
parente044924ee508e87c07df1385f3dfddb739b7faaa (diff)
rexml: Fix XPath string() implementation
* lib/rexml/functions.rb( REXML::Functions.string): * Support context node. * Fix implementation for document node to remove out of root nodes. * Support processing instruction node. * Improve implementation for integer to omit decimals. * test/rexml/test_jaxen.rb: Enable processing instruction test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rexml/functions.rb33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/rexml/functions.rb b/lib/rexml/functions.rb
index b84209619d..0f91fcd23f 100644
--- a/lib/rexml/functions.rb
+++ b/lib/rexml/functions.rb
@@ -136,21 +136,36 @@ module REXML
# An object of a type other than the four basic types is converted to a
# string in a way that is dependent on that type.
def Functions::string( object=nil )
- #object = @context unless object
- if object.instance_of? Array
- string( object[0] )
- elsif defined? object.node_type
- if object.node_type == :attribute
+ object = @@context[:node] if object.nil?
+ if object.respond_to?(:node_type)
+ case object.node_type
+ when :attribute
object.value
- elsif object.node_type == :element || object.node_type == :document
+ when :element
string_value(object)
+ when :document
+ string_value(object.root)
+ when :processing_instruction
+ object.content
else
object.to_s
end
- elsif object.nil?
- return ""
else
- object.to_s
+ case object
+ when Array
+ string(object[0])
+ when Numeric
+ integer = object.to_i
+ if object == integer
+ "%d" % integer
+ else
+ object.to_s
+ end
+ when nil
+ ""
+ else
+ object.to_s
+ end
end
end