nokogiri icon indicating copy to clipboard operation
nokogiri copied to clipboard

CSS query fails for empty element_children in JRuby

Open orhantoy opened this issue 7 years ago • 3 comments

Describe the bug

If the node set returned from Nokogiri::XML::Node#element_children is empty, querying it with .css raises an exception in JRuby. For MRI this works as expected by returning an empty node set.

To Reproduce

MRI 👍

$ RBENV_VERSION=2.5.3 ruby -I lib -r nokogiri -e "puts Nokogiri::XML('<root><row></row></root>').at_css('row').element_children.css('column').inspect"
[]

JRuby 👎

$ RBENV_VERSION=jruby-9.2.5.0 ruby -I lib -r nokogiri -e "puts Nokogiri::XML('<root><row></row></root>').at_css('row').element_children.css('column').inspect"
NoMethodError: undefined method `root' for nil:NilClass
  extract_params at [...]/nokogiri/lib/nokogiri/xml/searchable.rb:224
             css at [...]/nokogiri/lib/nokogiri/xml/node_set.rb:80
          <main> at -e:1

Expected behavior

I would expect the JRuby variant not to blow up and instead return an empty node set as with MRI.

orhantoy avatar Apr 30 '19 14:04 orhantoy

Thanks for reporting this! I'll take a look as soon as I can.

flavorjones avatar May 13 '19 12:05 flavorjones

@orhantoy Sorry for the delay on this -- I've not been able to work very much on OSS the past six months or so. Hopefully that'll be changing shortly.

In any case, this is a note for myself from our email thread -- which is to remember offer to pair with you when I do get to this.

flavorjones avatar Jun 26 '20 18:06 flavorjones

@flavorjones All good, welcome back :v:

If you get the time it would be helpful to pair on this as I recall having some trouble debugging the issue.

orhantoy avatar Jun 30 '20 11:06 orhantoy