diff options
Diffstat (limited to 'lib/rexml')
-rw-r--r-- | lib/rexml/parsers/xpathparser.rb | 15 | ||||
-rw-r--r-- | lib/rexml/xpath_parser.rb | 18 |
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb index 304dc51698..ac3c4d4e67 100644 --- a/lib/rexml/parsers/xpathparser.rb +++ b/lib/rexml/parsers/xpathparser.rb @@ -271,10 +271,12 @@ module REXML # String, if a name match #NodeTest # | ('*' | NCNAME ':' '*' | QNAME) NameTest - # | NODE_TYPE '(' ')' NodeType + # | '*' ':' NCNAME NameTest since XPath 2.0 + # | NODE_TYPE '(' ')' NodeType # | PI '(' LITERAL ')' PI # | '[' expr ']' Predicate - NCNAMETEST= /^(#{NCNAME_STR}):\*/u + PREFIX_WILDCARD = /^\*:(#{NCNAME_STR})/u + LOCAL_NAME_WILDCARD = /^(#{NCNAME_STR}):\*/u QNAME = Namespace::NAMESPLIT NODE_TYPE = /^(comment|text|node)\(\s*\)/m PI = /^processing-instruction\(/ @@ -282,6 +284,13 @@ module REXML original_path = path path = path.lstrip case path + when PREFIX_WILDCARD + prefix = nil + name = $1 + path = $' + parsed << :qname + parsed << prefix + parsed << name when /^\*/ path = $' parsed << :any @@ -301,7 +310,7 @@ module REXML end parsed << :processing_instruction parsed << (literal || '') - when NCNAMETEST + when LOCAL_NAME_WILDCARD prefix = $1 path = $' parsed << :namespace diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index a94ad91ea1..d217ae78e8 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -169,16 +169,20 @@ module REXML prefix = path_stack.shift name = path_stack.shift # enter(:qname, path_stack, prefix, name, nodeset) - nodeset.delete_if do |node| - # FIXME: This DOUBLES the time XPath searches take - ns = get_namespace( node, prefix ) + nodeset.select! do |node| if node.node_type == :element - if node.name == name + if prefix.nil? + node.name == name + elsif prefix.empty? + node.name == name and node.namespace == "" + else + node.name == name and + # FIXME: This DOUBLES the time XPath searches take + node.namespace == get_namespace(node, prefix) end + else + false end - !(node.node_type == :element and - node.name == name and - node.namespace == ns ) end # leave(:qname, path_stack, nodeset) node_types = ELEMENTS |