Skip to content

Commit 4b25c28

Browse files
authored
Improve dash detection (#16)
1 parent 8c37b71 commit 4b25c28

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

css.escape.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
var codeUnit;
2929
var result = '';
3030
var firstCodeUnit = string.charCodeAt(0);
31+
32+
if (
33+
// If the character is the first character and is a `-` (U+002D), and
34+
// there is no second character, […]
35+
length == 1 &&
36+
firstCodeUnit == 0x002D
37+
) {
38+
return '\\' + string;
39+
}
40+
3141
while (++index < length) {
3242
codeUnit = string.charCodeAt(index);
3343
// Note: there’s no need to special-case astral symbols, surrogate
@@ -60,17 +70,6 @@
6070
continue;
6171
}
6272

63-
if (
64-
// If the character is the first character and is a `-` (U+002D), and
65-
// there is no second character, […]
66-
index == 0 &&
67-
length == 1 &&
68-
codeUnit == 0x002D
69-
) {
70-
result += '\\' + string.charAt(index);
71-
continue;
72-
}
73-
7473
// If the character is not handled by one of the above rules and is
7574
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
7675
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
@@ -91,7 +90,6 @@
9190
// Otherwise, the escaped character.
9291
// https://drafts.csswg.org/cssom/#escape-a-character
9392
result += '\\' + string.charAt(index);
94-
9593
}
9694
return result;
9795
};

0 commit comments

Comments
 (0)