1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rexml] xpath: fix a bug that no namespace attribute isn't matched with prefix

[ruby-list:50733]

Reported by Yasuhiro KIMURA. Thanks!!!

8f3c5c176a
This commit is contained in:
Kouhei Sutou 2018-12-31 07:21:37 +09:00 committed by Hiroshi SHIBATA
parent f76cfb55d7
commit 3583fa166c
2 changed files with 14 additions and 2 deletions

View file

@ -499,7 +499,11 @@ module REXML
else else
# FIXME: This DOUBLES the time XPath searches take # FIXME: This DOUBLES the time XPath searches take
ns = get_namespace(raw_node.element, prefix) ns = get_namespace(raw_node.element, prefix)
raw_node.name == name and raw_node.namespace == ns if ns.empty?
raw_node.name == name and raw_node.prefix.empty?
else
raw_node.name == name and raw_node.namespace == ns
end
end end
else else
false false

View file

@ -7,7 +7,7 @@ module REXMLTests
def setup def setup
@xml = <<-XML @xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<root> <root xmlns="http://example.com/">
<child name="one">child1</child> <child name="one">child1</child>
<child name="two">child2</child> <child name="two">child2</child>
<child name="three">child3</child> <child name="three">child3</child>
@ -26,5 +26,13 @@ module REXMLTests
children = REXML::XPath.each(@document, "/root/child[@name='two']") children = REXML::XPath.each(@document, "/root/child[@name='two']")
assert_equal(["child2"], children.collect(&:text)) assert_equal(["child2"], children.collect(&:text))
end end
def test_no_namespace
children = REXML::XPath.match(@document,
"/root/child[@nothing:name='two']",
"" => "http://example.com/",
"nothing" => "")
assert_equal(["child2"], children.collect(&:text))
end
end end
end end