Skip to content

className value not escaped when set using constructor #182

Open

Description

@adamwathan

Not sure if this is by design or not but I expected after #133 that class names would be escaped by default when creating a new className node.

const classNameA = parser.className({ value: 'hover:bg-blue' })
classNameA.toString()
// => '.hover:bg-blue'

const classNameB = parser.className()
classNameB.value = 'hover:bg-blue'
classNameB.toString()
// => '.hover\\:bg-blue'

Maybe @chriseppstein would know if this is intended or not? Seems weird to me to have to set the value through mutation in order to get the escaping behavior.

Activity

  1. alexander-akait commented on Mar 4, 2019

    @alexander-akait
    Collaborator

    Yep, looks like a bug in API, feel free to send a PR

  2. adamwathan commented on Mar 4, 2019

    @adamwathan
    ContributorAuthor

    The part I'm not sure about is that it seems very deliberate, you can see here that the escaping code is very intentionally only run if you are setting the value outside of the constructor:

    https://github.com/postcss/postcss-selector-parser/blob/master/src/selectors/className.js#L14

    So would be nice to hear from @chriseppstein to better understand why it works this way.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions