From c1a8b09fc37e306f1b74fc87af74a21183c40f50 Mon Sep 17 00:00:00 2001 From: tompng Date: Fri, 5 Jun 2026 21:41:32 +0900 Subject: [PATCH] Remove XPath namespace axis handling part which is not working at all Namespace axis should return a nodeset of Namespace Node, but Namespace Node class has not even been defined yet. --- lib/rexml/xpath_parser.rb | 27 +++------------------------ test/xpath/test_base.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index 02cd5056..c48eac76 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -223,30 +223,9 @@ def expr( path_stack, nodeset, context=nil ) nodesets end when :namespace - pre_defined_namespaces = { - "xml" => "http://www.w3.org/XML/1998/namespace", - } - nodeset = step(path_stack, any_type: :namespace) do - nodesets = [] - nodeset.each do |node| - raw_node = node.raw_node - case raw_node.node_type - when :element - if @namespaces - nodesets << pre_defined_namespaces.merge(@namespaces) - else - nodesets << pre_defined_namespaces.merge(raw_node.namespaces) - end - when :attribute - if @namespaces - nodesets << pre_defined_namespaces.merge(@namespaces) - else - nodesets << pre_defined_namespaces.merge(raw_node.element.namespaces) - end - end - end - nodesets - end + warn 'Namespace axis is not supported in REXML::XPathParser', uplevel: 1 + # TODO: We need to create NamespaceNode class to support this feature + nodeset = step(path_stack) { [] } when :parent nodeset = step(path_stack) do nodesets = [] diff --git a/test/xpath/test_base.rb b/test/xpath/test_base.rb index c7049d67..fce80cda 100644 --- a/test/xpath/test_base.rb +++ b/test/xpath/test_base.rb @@ -248,6 +248,14 @@ def test_axe_parent assert_equal 19, q.attributes["id"].to_i end + def test_axe_namespace_no_error + $VERBOSE, verbose = nil, $VERBOSE + # Although namespace axis is not implemented yet, it should not raise NoMethodError + XPath.match(@@doc, "a/d/c/namespace::*") + ensure + $VERBOSE = verbose + end + def test_abbreviated_attribute assert_equal 'a', XPath::first( @@doc, "a[@id='1']" ).name c = XPath::first( @@doc, "a/b/c[@id='4']" )