Skip to content

Node#> operator does not work in a DocumentFragment #1857

@flavorjones

Description

@flavorjones

Originally reported on the mailing list by @MaxLustig and at #1853 which was self-closed.

Failing example:

#! /usr/bin/env ruby

require 'nokogiri'

html = <<-EOHTML
    <div class="section header" id=1>
      <div class="subsection header">sub 1</div>
      <div class="subsection header">sub 2</div>
    </div>
    <div class="section header" id=2>
      <div class="subsection header">sub 3</div>
      <div class="subsection header">sub 4</div>
    </div>
EOHTML

doc = Nokogiri::HTML.fragment html

parent = doc.at_css("body")

x = parent > ".header"
# /home/flavorjones/foo.rb:22:in `<main>': undefined method `>' for nil:NilClass (NoMethodError)

We should move the definition of Node#> into Searchable and make sure it works for DocumentFragment. I'll further note that that implementation might be fraught because of the well-documented xpath-on-root-nodes issues (see #572), but this is essentially a failing test that we need to make work at some point.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions