sparklemotion / nokogiri

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
https://nokogiri.org/
MIT License
6.14k stars 899 forks source link

:eq css selector should index from zero #652

Open mattheworiordan opened 12 years ago

mattheworiordan commented 12 years ago

I read on https://github.com/tenderlove/nokogiri/wiki/From-jQuery-Traversing about using :eq for traversing and selecting an element using Nokogiri, which is great... untilI discovered that :eq(1) refers to the first element with Nokogiri, and in JQuery it refers to the second element (zero indexed), see http://api.jquery.com/eq/. As I interchangeably use my CSS selectors in client-side Javascript tests and Capybara tests, this is causing endless issues.

I propose that :eq should be compatible with JQuery and use an zero based index.

mattheworiordan commented 12 years ago

Sorry, I should have added this in for reference, http://stackoverflow.com/questions/4124523/what-library-does-capybara-use-as-css-selector. I have seen a few mentions online of people experiencing the same surprise.

flavorjones commented 12 years ago

See https://github.com/tenderlove/nokogiri/issues/628 for related bug report.

Because this sort of change can break lots of things in bad ways, we're planning on addressing JQuery compatibility in 2.0. You can read more about the roadmap here: https://github.com/tenderlove/nokogiri/blob/master/ROADMAP.md

I'll add this issue to the roadmap.

mattheworiordan commented 12 years ago

Thanks for the reply, makes sense to make this part of a bigger update as you're right, it could certainly break things.