problem with :contains selector [1.2.1 regression]

Jack Cushman avatarJack Cushman created an issue


The switch to cssselect introduced a bug with the :contains selector, which doesn't seem to work right in JQueryTranslator.


In cssselect, :contains() works fine:

>>> import cssselect.xpath
>>> t = cssselect.xpath.GenericTranslator()
>>> t.css_to_xpath(':contains("Your first name and initial")')
u"descendant-or-self::*[contains(string(.), 'Your first name and initial')]"

In JQueryTranslator, :contains() is broken:

>>> from pyquery.cssselectpatch import JQueryTranslator
>>> t = JQueryTranslator()
>>> t.css_to_xpath(':contains("Your first name and initial")')
u"descendant-or-self::*[contains(text(), '**[<STRING 'Your first name and initial' at 10>]**')]"

The easiest fix is just to remove xpath_contains_function from entirely, and let it fall through to GenericTranslator. But if there's some reason not to do that, it looks like you need to do the string conversion the way it's done in GenericTranslator:

'contains(string(.), %s)' % self.xpath_literal(value)

It might also be worth taking a look at xpath_lt_function etc, which also seem to be accessing function.arguments directly in a way that might not work so well -- I didn't actually test those ones.

VERSIONS: I reproduced this bug on OS X 10.7.4, Python 2.7.1, pyquery 1.2.1. I wasn't able to reproduce it with ActivePython on Windows -- but I might have just been looking at an earlier version of pyquery or something.

(This may have been a little confused -- let me know if you need more details.)

Thanks! Jack

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.