Skip to content

fix: don't double-escape scoped names with postcss-selector-parser 7.2.0 - #71

Open
denniskigen wants to merge 1 commit into
css-modules:masterfrom
denniskigen:fix/double-escaped-scoped-names
Open

denniskigen wants to merge 1 commit into
css-modules:masterfrom
denniskigen:fix/double-escaped-scoped-names

Conversation

@denniskigen

Copy link
Copy Markdown

postcss-selector-parser 7.2.0 started escaping values passed to the className() constructor (postcss/postcss-selector-parser#349). We pass it a scoped name that's already escaped (css-loader escapes the name before returning it from generateScopedName), so it now gets escaped twice. A name like F+JnE5oCZsS0FV+Mxzn6Mg== comes out as .F\\\+JnE5oCZsS0FV\\\+Mxzn6Mg\\\=\\\=, which doesn't match the exported class, so the styles never apply. We hit this in OpenMRS, where every CSS module class in our app shell stopped matching. Reported in postcss/postcss-selector-parser#362.

This passes the unescaped name as value and the escaped spelling as raws.value, which is how the parser represents a class it parsed itself. The parser leaves raws.value alone, so the output is the same on 7.0.0, 7.1.8 and 7.2.0. I've done the same for ids, since postcss/postcss-selector-parser#360 makes the id() constructor escape too.

With value unescaped, the check that keeps the space after a trailing hex escape (.\1F600 .foo) has to look at the serialised spelling, so it now uses stringifyProperty("value"). Without that, escape-sequence fails.

The new escaped-scoped-names case returns pre-escaped names the way css-loader does. It fails on 7.2.0 without this change.

postcss-selector-parser 7.2.0 escapes values passed to the className()
constructor. The scoped name we pass is already escaped (css-loader
escapes it in generateScopedName), so it was escaped twice and the
selector no longer matched the exported class.

Pass the unescaped name as `value` and the escaped spelling as
`raws.value`, matching how the parser represents a class it parsed
itself. Do the same for ids, which postcss-selector-parser#360 would
also start escaping. The trailing hex escape check now reads the
serialised spelling, since `value` is no longer escaped.
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

Successfully merging this pull request may close these issues.

1 participant