Skip to content

Commit 8f3c5c1

Browse files
committed
xpath: fix a bug that no namespace attribute isn't matched with prefix
[ruby-list:50733] Reported by Yasuhiro KIMURA. Thanks!!!
1 parent 4e4d8d6 commit 8f3c5c1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/rexml/xpath_parser.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ def node_test(path_stack, nodesets, any_type: :element)
499499
else
500500
# FIXME: This DOUBLES the time XPath searches take
501501
ns = get_namespace(raw_node.element, prefix)
502-
raw_node.name == name and raw_node.namespace == ns
502+
if ns.empty?
503+
raw_node.name == name and raw_node.prefix.empty?
504+
else
505+
raw_node.name == name and raw_node.namespace == ns
506+
end
503507
end
504508
else
505509
false

test/rexml/xpath/test_attribute.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TestXPathAttribute < Test::Unit::TestCase
77
def setup
88
@xml = <<-XML
99
<?xml version="1.0" encoding="UTF-8"?>
10-
<root>
10+
<root xmlns="http://example.com/">
1111
<child name="one">child1</child>
1212
<child name="two">child2</child>
1313
<child name="three">child3</child>
@@ -26,5 +26,13 @@ def test_xpath_each
2626
children = REXML::XPath.each(@document, "/root/child[@name='two']")
2727
assert_equal(["child2"], children.collect(&:text))
2828
end
29+
30+
def test_no_namespace
31+
children = REXML::XPath.match(@document,
32+
"/root/child[@nothing:name='two']",
33+
"" => "http://example.com/",
34+
"nothing" => "")
35+
assert_equal(["child2"], children.collect(&:text))
36+
end
2937
end
3038
end

0 commit comments

Comments
 (0)