CSS query fails for empty element_children in JRuby
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.
Thanks for reporting this! I'll take a look as soon as I can.
@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 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.