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

Commit 6d5c5d8

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

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-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-]+(\(.+?\))?\s*/gi, (match, p1) => p1 === '\\' ? match : ' ').trim();
464464
}
465465
if (!sel) return false;
466466

test/__snapshots__/index.test.js.snap

+10-2
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ footer {
140140
margin-top: 1em;
141141
padding-top: 1em;
142142
border-top: thin dotted;
143+
}
144+
145+
.clazz\\\\:colon {
146+
color: green;
143147
}</style>
144148
</head>
145149
<body>
146-
<ul class=\\"navbar\\">
150+
<ul class=\\"navbar clazz:colon\\">
147151
<li>
148152
<a href=\\"index.html\\">Home page</a>
149153
</li>
@@ -368,10 +372,14 @@ exports[`webpack compilation 1`] = `
368372
.hidden {
369373
visibility: hidden;
370374
}
375+
376+
.clazz\\\\:colon {
377+
color: green;
378+
}
371379
</style>
372380
</head>
373381
<body>
374-
<ul class=\\"navbar\\">
382+
<ul class=\\"navbar clazz:colon\\">
375383
<li>
376384
<a href=\\"index.html\\">Home page</a>
377385
</li>

test/__snapshots__/standalone.test.js.snap

+5-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ footer {
7676
margin-top: 1em;
7777
padding-top: 1em;
7878
border-top: thin dotted;
79+
}
80+
81+
.clazz\\\\:colon {
82+
color: green;
7983
}</style>
8084
</head>
8185
<body>
82-
<ul class=\\"navbar\\">
86+
<ul class=\\"navbar clazz:colon\\">
8387
<li>
8488
<a href=\\"index.html\\">Home page</a>
8589
</li>

test/fixtures/basic/index.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,14 @@
5454
.hidden {
5555
visibility: hidden;
5656
}
57+
58+
.clazz\:colon {
59+
color: green;
60+
}
5761
</style>
5862
</head>
5963
<body>
60-
<ul class="navbar">
64+
<ul class="navbar clazz:colon">
6165
<li>
6266
<a href="index.html">Home page</a>
6367
</li>

0 commit comments

Comments
 (0)