Nokogiri::XML::NodeSet #first(5) includes nils

17 views
Skip to first unread message

Andrew Derenge

unread,
Jun 9, 2017, 8:02:23 AM6/9/17
to nokogiri-talk
Hi, first time poster so please let me know if I should be asking this somewhere else or should be phrasing my question differently.

When using first on a NodeSet with an argument, I am receiving nils in the array. I would expect the behavior to be similar to the ruby doc enumerable description of first.

An example from ruby doc being:

%w[foo bar baz].first(10) #=> ["foo", "bar", "baz"]


What I expect:

Nokogiri::HTML('<a></a><a></a>').css('a').first(3)
[#<Nokogiri::XML::Element:0x3fc3dfd5f1c8 name="a">, #<Nokogiri::XML::Element:0x3fc3dfd5f1b4 name="a">]


What I get:

Nokogiri::HTML('<a></a><a></a>').css('a').first(3)
[#<Nokogiri::XML::Element:0x3fc3dfd5f1c8 name="a">, #<Nokogiri::XML::Element:0x3fc3dfd5f1b4 name="a">, nil]

Is this expected behavior?

Thanks for reading and any direction would be appreciated!



Mike Dalessio

unread,
Jun 9, 2017, 8:03:31 AM6/9/17
to nokogiri-talk
Hi Andrew,

Thanks for asking this question. This seems like a bug to me. Would you mind opening a github issue?


--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-talk+unsubscribe@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at https://groups.google.com/group/nokogiri-talk.
For more options, visit https://groups.google.com/d/optout.

Andrew Derenge

unread,
Jun 12, 2017, 1:49:08 PM6/12/17
to nokogiri-talk
Hey Mike,

Thank you for the direction, I'll open a github issue this evening.


On Friday, June 9, 2017 at 7:03:31 AM UTC-5, Mike Dalessio wrote:
Hi Andrew,

Thanks for asking this question. This seems like a bug to me. Would you mind opening a github issue?

On Jun 9, 2017 8:02 AM, "Andrew Derenge" <arde...@gmail.com> wrote:
Hi, first time poster so please let me know if I should be asking this somewhere else or should be phrasing my question differently.

When using first on a NodeSet with an argument, I am receiving nils in the array. I would expect the behavior to be similar to the ruby doc enumerable description of first.

An example from ruby doc being:

%w[foo bar baz].first(10) #=> ["foo", "bar", "baz"]


What I expect:

Nokogiri::HTML('<a></a><a></a>').css('a').first(3)
[#<Nokogiri::XML::Element:0x3fc3dfd5f1c8 name="a">, #<Nokogiri::XML::Element:0x3fc3dfd5f1b4 name="a">]


What I get:

Nokogiri::HTML('<a></a><a></a>').css('a').first(3)
[#<Nokogiri::XML::Element:0x3fc3dfd5f1c8 name="a">, #<Nokogiri::XML::Element:0x3fc3dfd5f1b4 name="a">, nil]

Is this expected behavior?

Thanks for reading and any direction would be appreciated!



--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages