Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit cf38bdf

Browse files
committed
fix: handle classes with colons
Class names can have `:` if they are escapped. Example: `.flex\:box`
1 parent 0f0bf76 commit cf38bdf

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export default class Critters {
460460
// Strip pseudo-elements and pseudo-classes, since we only care that their associated elements exist.
461461
// This means any selector for a pseudo-element or having a pseudo-class will be inlined if the rest of the selector matches.
462462
if (sel !== ':root') {
463-
sel = sel.replace(/(::?[a-z-]+(\(.+?\))?\s*)/gi, ' ').trim();
463+
sel = sel.replace(/(?<!\\)::?[a-z-]+(?![a-z-(])/gi, '').replace(/::?not\(\s*\)/g, '').trim();
464464
}
465465
if (!sel) return false;
466466

test/__snapshots__/index.test.js.snap

+17-2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ ul.navbar:not(.hidden) li:hover a {
124124
color: black;
125125
}
126126
127+
ul.navbar:not(:hover) li:hover a {
128+
color: black;
129+
}
130+
127131
ul.navbar li:hover a {
128132
color: red;
129133
}
@@ -140,10 +144,14 @@ footer {
140144
margin-top: 1em;
141145
padding-top: 1em;
142146
border-top: thin dotted;
147+
}
148+
149+
.clazz\\\\:colon {
150+
color: green;
143151
}</style>
144152
</head>
145153
<body>
146-
<ul class=\\"navbar\\">
154+
<ul class=\\"navbar clazz:colon\\">
147155
<li>
148156
<a href=\\"index.html\\">Home page</a>
149157
</li>
@@ -347,6 +355,9 @@ exports[`webpack compilation 1`] = `
347355
ul.navbar:not(.hidden) li:hover a {
348356
color: black;
349357
}
358+
ul.navbar:not(:hover) li:hover a {
359+
color: black;
360+
}
350361
ul.navbar li:hover a {
351362
color: red;
352363
}
@@ -368,10 +379,14 @@ exports[`webpack compilation 1`] = `
368379
.hidden {
369380
visibility: hidden;
370381
}
382+
383+
.clazz\\\\:colon {
384+
color: green;
385+
}
371386
</style>
372387
</head>
373388
<body>
374-
<ul class=\\"navbar\\">
389+
<ul class=\\"navbar clazz:colon\\">
375390
<li>
376391
<a href=\\"index.html\\">Home page</a>
377392
</li>

test/__snapshots__/standalone.test.js.snap

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ul.navbar:not(.hidden) li:hover a {
6060
color: black;
6161
}
6262
63+
ul.navbar:not(:hover) li:hover a {
64+
color: black;
65+
}
66+
6367
ul.navbar li:hover a {
6468
color: red;
6569
}
@@ -76,10 +80,14 @@ footer {
7680
margin-top: 1em;
7781
padding-top: 1em;
7882
border-top: thin dotted;
83+
}
84+
85+
.clazz\\\\:colon {
86+
color: green;
7987
}</style>
8088
</head>
8189
<body>
82-
<ul class=\\"navbar\\">
90+
<ul class=\\"navbar clazz:colon\\">
8391
<li>
8492
<a href=\\"index.html\\">Home page</a>
8593
</li>

test/fixtures/basic/index.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
ul.navbar:not(.hidden) li:hover a {
3434
color: black;
3535
}
36+
ul.navbar:not(:hover) li:hover a {
37+
color: black;
38+
}
3639
ul.navbar li:hover a {
3740
color: red;
3841
}
@@ -54,10 +57,14 @@
5457
.hidden {
5558
visibility: hidden;
5659
}
60+
61+
.clazz\:colon {
62+
color: green;
63+
}
5764
</style>
5865
</head>
5966
<body>
60-
<ul class="navbar">
67+
<ul class="navbar clazz:colon">
6168
<li>
6269
<a href="index.html">Home page</a>
6370
</li>

0 commit comments

Comments
 (0)