Skip to content

[cssom][css-escape][css-selectors]: Using CSS.escape with nth-child #2306

@jridgewell

Description

@jridgewell

We've just gone though our codebase to enforce using CSS.escape on any dynamic parts of a selector. The only caveat we've found so far is with :nth-child and friends, due to the very limited set of parsing of An+b

// Works fine
querySelector(`div.${CSS.escape(3)}`);

// Throws parse error
querySelector(`div:nth-child(${CSS.escape(3)})`);

Is CSS.escape meant to handle this situation? Or, should the An+b syntax be loosened to allow escaped numbers?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions