Skip to content

Commit

Permalink
Fix @import regex bit which was stopping consumption in the middle of…
Browse files Browse the repository at this point in the history
… a url - need to consume quotes.

Thanks dave.kindel@pendo.io for reporting and isolating this case
  • Loading branch information
eoghanmurray committed May 22, 2024
1 parent a88db42 commit de2363a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
*/

function _compileAtrule(name: string) {
const re = new RegExp('^@' + name + '\\s*([^;]+);');
const re = new RegExp(
'^@' +
name +
'\\s*((?:' +
[
'(?<!\\\\)"(?:\\\\"|[^"])*"',
"(?<!\\\\)'(?:\\\\'|[^'])*'",
'[^;]',
].join('|') +
')+);',
);
return () => {
const pos = position();
const m = match(re);
Expand Down
9 changes: 9 additions & 0 deletions packages/rrweb-snapshot/test/rebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,13 @@ ul li.specified c:hover img, ul li.specified c.\\:hover img {
should_not_modify,
);
});

it('should not incorrectly interpret at rules', () => {
// the ':hover' in the below is a decoy which is not part of the selector,
const should_not_modify =
'@import url("https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,400;0,500;0,700;1,400&display=:hover");';
expect(adaptCssForReplay(should_not_modify, cache)).toEqual(
should_not_modify,
);
});
});

0 comments on commit de2363a

Please sign in to comment.