[lxml-dev] Potential bug when using nth-child in CSSSelector

Stefan Behnel stefan_ml at behnel.de
Sun Jun 22 11:15:49 CEST 2008


Hi,

thanks for the report.

John Evans wrote:
> I have observed some unexpected behavior with lxml -- I looked in the bug
> tracker and didn't see anything that seemed related to this.
> 
> daedalus:~ john$ python
> Python 2.5.2 Stackless 3.1b3 060516 (python-2.52:61022, Feb 27 2008,
> 16:52:03)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from lxml.cssselect import CSSSelector
>>>> CSSSelector("div div:nth-child(5) div div div:nth-child(3) img").path
> "descendant-or-self::div/descendant::*[name() = 'div' and (position() = 5)]"
> 
> It looks like when you use the nth-child member in a CSSSelector it chops
> off the rest of the CSSSelector and does not process it when compiling it
> down to an xpath.

That was an indentation bug (i.e. wrong block-level) in the selector parser,
which made it stop short after a (pseudo) function with parameters.

Here's a fixed version for 2.0:

http://codespeak.net/svn/lxml/branch/lxml-2.0/src/lxml/cssselect.py

or for 2.1 beta:

http://codespeak.net/svn/lxml/trunk/src/lxml/cssselect.py

Stefan


More information about the lxml-dev mailing list