Skip to content

css_to_xpath |= with an empty value matches elements without the attribute #1109

Description

@gaborbernat

css_to_xpath translates [d|="" i], and p[lang|=""] (HTML compares lang values case-insensitively), into translate(@d, ...) = '' or starts-with(...), which is true for an element without the attribute because string() of an empty node-set is the empty string. On <div><p id=none/><p id=empty d=""/><p id=dash d="-x"/></div>, select('[d|="" i]') returns empty and dash, while the XPath on lxml 6.1.3 also returns the div and none.

Selectors 4 matches [att|=val] only on elements that have att. #1086 added the presence guard for =; |= needs the same one. cssselect 1.5.0 guards every |= match on the attribute.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions