mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rexml] Fix crash with nil XPath variables (#13)
Patch by Alyssa Ross. Thanks!!! https://github.com/ruby/rexml/commit/2a53c54f58
This commit is contained in:
parent
982208c650
commit
ee8985ef0e
2 changed files with 20 additions and 4 deletions
|
@ -135,8 +135,7 @@ module REXML
|
||||||
#
|
#
|
||||||
# An object of a type other than the four basic types is converted to a
|
# 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.
|
# string in a way that is dependent on that type.
|
||||||
def Functions::string( object=nil )
|
def Functions::string( object=@@context[:node] )
|
||||||
object = @@context[:node] if object.nil?
|
|
||||||
if object.respond_to?(:node_type)
|
if object.respond_to?(:node_type)
|
||||||
case object.node_type
|
case object.node_type
|
||||||
when :attribute
|
when :attribute
|
||||||
|
@ -165,8 +164,6 @@ module REXML
|
||||||
object.to_s
|
object.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when nil
|
|
||||||
""
|
|
||||||
else
|
else
|
||||||
object.to_s
|
object.to_s
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,12 @@ require "rexml/document"
|
||||||
module REXMLTests
|
module REXMLTests
|
||||||
class FunctionsTester < Test::Unit::TestCase
|
class FunctionsTester < Test::Unit::TestCase
|
||||||
include REXML
|
include REXML
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
REXML::Functions.context = nil
|
||||||
|
end
|
||||||
|
|
||||||
def test_functions
|
def test_functions
|
||||||
# trivial text() test
|
# trivial text() test
|
||||||
# confuse-a-function
|
# confuse-a-function
|
||||||
|
@ -222,6 +228,19 @@ module REXMLTests
|
||||||
assert_equal( [REXML::Comment.new("COMMENT A")], m )
|
assert_equal( [REXML::Comment.new("COMMENT A")], m )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_string_nil_without_context
|
||||||
|
doc = REXML::Document.new(<<-XML)
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<root>
|
||||||
|
<foo bar="baz"/>
|
||||||
|
<foo bar=""/>
|
||||||
|
</root>
|
||||||
|
XML
|
||||||
|
|
||||||
|
m = REXML::XPath.match(doc, "//foo[@bar=$n]", nil, { "n" => nil })
|
||||||
|
assert_equal( 1, m.size )
|
||||||
|
end
|
||||||
|
|
||||||
def test_unregistered_method
|
def test_unregistered_method
|
||||||
doc = Document.new("<root/>")
|
doc = Document.new("<root/>")
|
||||||
assert_nil(XPath::first(doc.root, "to_s()"))
|
assert_nil(XPath::first(doc.root, "to_s()"))
|
||||||
|
|
Loading…
Reference in a new issue