Skip to content

Commit 16c960f

Browse files
authored
Ensure identifiers are escaped properly (#504)
1 parent 3a36820 commit 16c960f

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

.changeset/flat-games-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
Ensure identifiers are escaped properly

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"start": "pnpm start-fixture themed",
1313
"start-site": "manypkg run site start",
1414
"build-site": "manypkg run site build",
15-
"postinstall": "pnpm dev",
1615
"test:jest": "jest",
1716
"test:playwright": "playwright test",
1817
"format": "prettier --write .",

packages/css/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"csstype": "^3.0.7",
4848
"deep-object-diff": "^1.1.0",
4949
"deepmerge": "^4.2.2",
50+
"escape-string-regexp": "^4.0.0",
5051
"outdent": "^0.8.0"
5152
},
5253
"devDependencies": {

packages/css/src/transformCss.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('transformCss', () => {
1111
expect(
1212
transformCss({
1313
composedClassLists: [],
14-
localClassNames: ['test_1/2_className'],
14+
localClassNames: ['test_1/2_className', '[test_with_brackets]'],
1515
cssObjs: [
1616
{
1717
type: 'local',
@@ -28,12 +28,22 @@ describe('transformCss', () => {
2828
},
2929
},
3030
},
31+
{
32+
type: 'local',
33+
selector: '[test_with_brackets]',
34+
rule: {
35+
color: 'blue',
36+
},
37+
},
3138
],
3239
}).join('\n'),
3340
).toMatchInlineSnapshot(`
3441
".test_1\\\\/2_className {
3542
color: red;
3643
}
44+
.\\\\[test_with_brackets\\\\] {
45+
color: blue;
46+
}
3747
@media screen and (min-width: 700px) {
3848
.test_1\\\\/2_className {
3949
color: green;

packages/css/src/transformCss.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getVarName } from '@vanilla-extract/private';
22
import cssesc from 'cssesc';
3+
import escapeStringRegexp from 'escape-string-regexp';
34

45
import type {
56
CSS,
@@ -105,7 +106,7 @@ class Stylesheet {
105106
this.keyframesRules = [];
106107
this.localClassNameRegex =
107108
localClassNames.length > 0
108-
? RegExp(`(${localClassNames.join('|')})`, 'g')
109+
? RegExp(`(${localClassNames.map(escapeStringRegexp).join('|')})`, 'g')
109110
: null;
110111

111112
// Class list compositions should be priortized by Newer > Older

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)