diff options
author | Kouhei Sutou <[email protected]> | 2018-12-31 07:21:37 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2019-08-04 11:54:00 +0900 |
commit | 3583fa166c52aff1ac6fab310e9133c553efcc4a (patch) | |
tree | 0e195bc26659fd0603e4d251c89b69b47e7b51aa | |
parent | f76cfb55d7612f1bb1648112e159646321d2aa2c (diff) |
[ruby/rexml] xpath: fix a bug that no namespace attribute isn't matched with prefix
[ruby-list:50733]
Reported by Yasuhiro KIMURA. Thanks!!!
https://github.com/ruby/rexml/commit/8f3c5c176a
-rw-r--r-- | lib/rexml/xpath_parser.rb | 6 | ||||
-rw-r--r-- | test/rexml/xpath/test_attribute.rb | 10 |
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index e30581d3d0..47fa4ef84e 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -499,7 +499,11 @@ module REXML else # FIXME: This DOUBLES the time XPath searches take 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 else false diff --git a/test/rexml/xpath/test_attribute.rb b/test/rexml/xpath/test_attribute.rb index 9304db4e0d..713d77b22f 100644 --- a/test/rexml/xpath/test_attribute.rb +++ b/test/rexml/xpath/test_attribute.rb @@ -7,7 +7,7 @@ module REXMLTests def setup @xml = <<-XML <?xml version="1.0" encoding="UTF-8"?> -<root> +<root xmlns="http://example.com/"> <child name="one">child1</child> <child name="two">child2</child> <child name="three">child3</child> @@ -26,5 +26,13 @@ module REXMLTests children = REXML::XPath.each(@document, "/root/child[@name='two']") assert_equal(["child2"], children.collect(&:text)) 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 |