Skip to content

Commit 3a88aa3

Browse files
authored
Cope with backslash selectors (#426)
* cope with backslash: selectors * function name
1 parent c17b1c9 commit 3a88aa3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ function memoize(fn) {
2727
* @return {string}
2828
*/
2929
const reduceCSSSelector = memoize((selector) => {
30-
return selector.split(
31-
/:(?=([^"'\\]*(\\.|["']([^"'\\]*\\.)*[^"'\\]*['"]))*[^"']*$)/g
32-
)[0];
30+
selector = selector.replace('\\:', '_ESCAPED_COLON_');
31+
return selector
32+
.split(/:(?=([^"'\\]*(\\.|["']([^"'\\]*\\.)*[^"'\\]*['"]))*[^"']*$)/g)[0]
33+
.replace('_ESCAPED_COLON_', '\\:');
3334
});
3435

3536
/**

tests/utils.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ test('Test reduceCSSSelector', async () => {
2020
expect(f("a[href^='javascript:']:after")).toEqual("a[href^='javascript:']");
2121
});
2222

23+
test('Test backslash selectors', async () => {
24+
expect(utils.reduceCSSSelector('foo\\:hover')).toEqual('foo\\:hover');
25+
});
26+
2327
test('Test parentSelectors', async () => {
2428
const f = utils.getParentSelectors;
2529
// Simplest possible

0 commit comments

Comments
 (0)