Ticket #107 (new defect)

Opened 11 months ago

:nth-child miscounting elements

Reported by: ardekantur Owned by: why
Priority: major Milestone:
Component: ext/hpricot_scan Version:
Keywords: Cc:

Description

Giving hpricot a simple table such as:

     +--------+--------+--------+--------+
     | Hea... | Hea... | Hea... | Hea... |
     +--------+--------+--------+--------+
     |      A |      B |      C |      D |
     +--------+--------+--------+--------+

produces bizarre results when iterating through all table rows that are not the first-child of the table.

>> h = Hpricot("<table><tr><th>Header</th><th>Header</th><th>Header</th><th>Header</th></tr><tr><td>A</td><td>B</td><td>C</td><td>D</td></tr></table>")
=> #<Hpricot::Doc {elem <table> {elem <tr> {elem <th> "Header" </th>} {elem <th> "Header" </th>} {elem <th> "Header" </th>} {elem <th> "Header" </th>} </tr>} {elem <tr> {elem <td> "A" </td>} {elem <td> "B" </td>} {elem <td> "C" </td>} {elem <td> "D" </td>} </tr>} </table>}>
>> (h/"table>tr:not(:first-child)").each do | i |
?> pp i/"td:nth-child(0)"
>> end
#<Hpricot::Elements[{elem <td> "B" </td>}]>

In order to retrieve the td element with content "A", I need to use 'i/"td:nth-child(-1)", which clearly isn't correct. The expected behavior is to be able to retrieve the td element with content "A" by using 'i/"td:nth-child(1)"', as CSS selectors begin at 1 instead of zero.

Note: See TracTickets for help on using tickets.