Skip to content

Commit

Permalink
Don't strip pseudo classes that are preceded by a backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 8, 2024
1 parent 4acf4ec commit f270b9d
Show file tree
Hide file tree
Showing 3 changed files with 24 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
19 changes: 19 additions & 0 deletions test/fontTracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ describe('fontTracer', function () {
]);
});

// https://github.com/Munter/subfont/issues/173
it('should foo', function () {
const htmlText = [
'<style>.font-family\\:default {font-family: foo;}</style>',
'<h1 class="font-family:default">text</h1>',
].join('');

return expect(htmlText, 'to satisfy computed font properties', [
{
text: 'text',
props: {
'font-family': 'foo',
'font-weight': 'bold',
'font-style': 'normal',
},
},
]);
});

it('should return font-weight as a string', function () {
const htmlText = '<style>body { font-weight: 500; }</style>text';

Expand Down
4 changes: 4 additions & 0 deletions test/stripPseudoClassesFromSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ describe('stripPseudoClassesFromSelector', function () {
it('should replace multiple consecutive pseudo class selectors directly following a selector with nothing', function () {
expect(strip('div:hover:focus:visited'), 'to be', 'div');
});

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

0 comments on commit f270b9d

Please sign in to comment.