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

className value not escaped when set using constructor #182

Open
adamwathan opened this issue Feb 27, 2019 · 2 comments
Open

className value not escaped when set using constructor #182

adamwathan opened this issue Feb 27, 2019 · 2 comments
Labels

Comments

@adamwathan
Copy link
Contributor

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.

@alexander-akait
Copy link
Collaborator

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

@adamwathan
Copy link
Contributor Author

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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants