Thanks to visit codestin.com
Credit goes to github.com

Skip to content

XPathParser#parse should work when node.document is nil #267

@pboling

Description

@pboling

Currently it will raise a NoMethodError.

    def parse path, node
      path_stack = @parser.parse( path )
      if node.is_a?(Array)
        Kernel.warn("REXML::XPath.each, REXML::XPath.first, REXML::XPath.match dropped support for nodeset...", uplevel: 1)
        return [] if node.empty?
        node = node.first
      end

      node.document.__send__(:enable_cache) do # <==== Will fail here
        match( path_stack, node )
      end
    end

Instead it should do:

if node.document
  node.document.__send__(:enable_cache) do
    match( path_stack, node )
  end
else
  match( path_stack, node )
end

This supercedes #260

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions