Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on selectors without namespace #84

Closed
fujimotos opened this issue Apr 6, 2018 · 1 comment
Closed

Exception on selectors without namespace #84

fujimotos opened this issue Apr 6, 2018 · 1 comment

Comments

@fujimotos
Copy link

Problem

The CSS3 spec allows the namespace field to be left empty, which indicates
an element with no namespace attached. However, cssselect cannot handle
those selectors right now.

For example, suppose we have the following line:

GenericTranslator().css_to_xpath('|foo')

This causes the parser to raise an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cssselect/cssselect/xpath.py", line 192, in css_to_xpath
    for selector in parse(css))
  File "/cssselect/cssselect/parser.py", line 354, in parse
    return list(parse_selector_group(stream))
  File "/cssselect/cssselect/parser.py", line 367, in parse_selector_group
    yield Selector(*parse_selector(stream))
  File "/cssselect/cssselect/parser.py", line 375, in parse_selector
    result, pseudo_element = parse_simple_selector(stream)
  File "/cssselect/cssselect/parser.py", line 475, in parse_simple_selector
    "Expected selector, got %s" % (peek,))
cssselect.parser.SelectorSyntaxError: Expected selector, got <DELIM '|' at 0>

Expected behaviour

cssselect should be able to handle a selector like |foo.

Note

Here is the related part from Selector Level 3 $6.1.1:

ns|E
    elements with name E in namespace ns 
*|E
    elements with name E in any namespace, including those without a namespace 
|E
    elements with name E without a namespace 
E
    if no default namespace has been declared for selectors, this is equivalent to *|E.
    Otherwise it is equivalent to ns|E where ns is the default namespace. 
@fujimotos
Copy link
Author

I just realized that the exact issue is already handled by #9.
So I close this ticket as ducplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant