Skip to content

Commit

Permalink
Ignore optional whitespace after combinators when parsing CSS selectors.
Browse files Browse the repository at this point in the history
For example, "div> .foo" was incorrectly parsed the same as "div>* .foo"
while it should be "div>.foo"
  • Loading branch information
SimonSapin committed Nov 4, 2011
1 parent 5fc9eac commit c57200a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lxml/cssselect.py
Expand Up @@ -693,6 +693,9 @@ def parse_selector(stream):
elif peek in ('+', '>', '~'):
# A combinator
combinator = stream.next()
# Ignore optional whitespace after a combinator
while stream.peek() == ' ':
stream.next()
else:
combinator = ' '
consumed = len(stream.used)
Expand Down
4 changes: 4 additions & 0 deletions src/lxml/tests/test_css.txt
Expand Up @@ -22,6 +22,10 @@ Then of parsing:
Or([Element[div], Class[Element[td].foo], CombinedSelector[Class[Element[div].bar] <followed> Element[span]]])
>>> parse('div > p')
CombinedSelector[Element[div] > Element[p]]
>>> parse('div>.foo')
CombinedSelector[Element[div] > Class[Element[*].foo]]
>>> parse('div > .foo')
CombinedSelector[Element[div] > Class[Element[*].foo]]
>>> parse('td:first')
Pseudo[Element[td]:first]
>>> parse('a[name]')
Expand Down
2 changes: 2 additions & 0 deletions src/lxml/tests/test_css_select.txt
Expand Up @@ -140,6 +140,8 @@ Now, the tests:
li-div
>>> pcss('div > div')
empty
>>> pcss('div>.c', 'div > .c')
first-ol
>>> pcss('div + div')
foobar-div
>>> pcss('a ~ a')
Expand Down

0 comments on commit c57200a

Please sign in to comment.