Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make the removed CSS contains selector case sensitive #40

Closed
wants to merge 1 commit into from

2 participants

@lrowe

The contains CSS selector was removed from the spec. Make it case sensitive for simplicity, speed and to match jQuery's implementation.

@lrowe lrowe The contains CSS selector was removed from the spec. Make it case sen…
…sitive for simplicity, speed and to match jQuery's implementation.
87c2fd0
@scoder

I agree that this behaviour would be much nicer and cleaner. However, as you can see in this line, it clearly breaks code that currently works and I cannot see a compelling reason to do that.

@SimonSapin SimonSapin referenced this pull request
Merged

External cssselect #46

@scoder
Owner

Closing, functionality has moved into separate cssselect project.

@scoder scoder closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2012
  1. @lrowe

    The contains CSS selector was removed from the spec. Make it case sen…

    lrowe authored
    …sitive for simplicity, speed and to match jQuery's implementation.
This page is out of date. Refresh to see the latest.
View
14 src/lxml/cssselect.py
@@ -238,11 +238,12 @@ def _xpath_nth_last_of_type(self, xpath, expr):
def _xpath_contains(self, xpath, expr):
# text content, minus tags, must contain expr
+ # this selector was removed from the CSS3 spec
+ # case sensitive for speed, matching jQuery's implementation
if isinstance(expr, Element):
expr = expr._format_element()
- xpath.add_condition('contains(css:lower-case(string(.)), %s)'
- % xpath_literal(expr.lower()))
- # FIXME: Currently case insensitive matching doesn't seem to be happening
+ xpath.add_condition('contains(string(.), %s)'
+ % xpath_literal(expr))
return xpath
def _xpath_not(self, xpath, expr):
@@ -253,13 +254,6 @@ def _xpath_not(self, xpath, expr):
xpath.add_condition('not(%s)' % cond)
return xpath
-def _make_lower_case(context, s):
- return s.lower()
-
-ns = etree.FunctionNamespace('http://codespeak.net/lxml/css/')
-ns.prefix = 'css'
-ns['lower-case'] = _make_lower_case
-
class Pseudo(object):
"""
Represents selector:ident
View
2  src/lxml/tests/test_css.py
@@ -24,7 +24,7 @@ class CSSTestCase(HelperTestCase):
## Changed from original, because the original doesn't make sense.
## There really aren't that many occurrances of 'celia'
#('div:contains(CELIA)', 243),
- ('div:contains(CELIA)', 30),
+ ('div:contains(CELIA)', 26),
('div:nth-child(even)', 106),
('div:nth-child(2n)', 106),
('div:nth-child(odd)', 137),
View
4 src/lxml/tests/test_css.txt
@@ -129,13 +129,13 @@ Now of translation:
>>> xpath('E:root')
e[not(parent::*)]
>>> xpath('E:contains("foo")')
- e[contains(css:lower-case(string(.)), 'foo')]
+ e[contains(string(.), 'foo')]
>>> xpath('E.warning')
e[contains(concat(' ', normalize-space(@class), ' '), ' warning ')]
>>> xpath('E#myid')
e[@id = 'myid']
>>> xpath('E:not(:contains("foo"))')
- e[not(contains(css:lower-case(string(.)), 'foo'))]
+ e[not(contains(string(.), 'foo'))]
>>> xpath('E F')
e/descendant-or-self::*/f
>>> xpath('E > F')
View
2  src/lxml/tests/test_css_select.txt
@@ -129,7 +129,7 @@ Now, the tests:
empty
>>> pcss('*:contains("link")')
html, nil, outer-div, tag-anchor, nofollow-anchor
- >>> pcss('*:contains("E")')
+ >>> pcss('*:contains("e")')
html, nil, outer-div, first-ol, first-li, paragraph, p-em
>>> pcss('.a', '.b', '*.a', 'ol.a')
first-ol
Something went wrong with that request. Please try again.