Skip to content

Commit

Permalink
Deal with unescaped colons preceded by escaped backslashes when strip…
Browse files Browse the repository at this point in the history
…ping pseudo classes
  • Loading branch information
papandreou committed May 8, 2024
1 parent 6eb7a3d commit 5c3f1bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stripPseudoClassesFromSelector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const multiPseudoClassMatcher =
/(?<!\\)(?::(?:active|any|checked|default|empty|enabled|fullscreen|focus|hover|indeterminate|in-range|invalid|link|optional|out-of-range|read-only|read-write|scope|target|valid|visited))+/gi;
/(?<=(?<!\\)(?:\\\\)*)(?::(?:active|any|checked|default|empty|enabled|fullscreen|focus|hover|indeterminate|in-range|invalid|link|optional|out-of-range|read-only|read-write|scope|target|valid|visited))+/gi;

const cssCombinators = [' ', '>', '+', '~', '/'];

Expand Down
16 changes: 16 additions & 0 deletions test/stripPseudoClassesFromSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ describe('stripPseudoClassesFromSelector', function () {
it('should not strip when the colon is escaped by a backslash', function () {
expect(strip('div\\:hover'), 'to be', 'div\\:hover');
});

it('should strip when the colon is escaped by a backslash that is itself escaped', function () {
expect(strip('div\\\\:hover'), 'to be', 'div\\\\');
});

it('should not strip when the colon is escaped by a backslash that is preceded by an escaped backslash', function () {
expect(strip('div\\\\\\:hover'), 'to be', 'div\\\\\\:hover');
});

it('should strip when the colon is escaped by two backslashes that are themselves escaped', function () {
expect(strip('div\\\\\\\\:hover'), 'to be', 'div\\\\\\\\');
});

it('should not strip when the colon is escaped by a backslash that is preceded by two escaped backslashes', function () {
expect(strip('div\\\\\\\\\\:hover'), 'to be', 'div\\\\\\\\\\:hover');
});
});

0 comments on commit 5c3f1bf

Please sign in to comment.