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 [email protected] for reporting and isolating this case
  • Loading branch information
eoghanmurray authored and jxiwang committed Jun 21, 2024
1 parent dc7b283 commit ecd7f3d
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 @@ -860,7 +860,17 @@ export function parse(css: string, options: ParserOptions = {}) {
*/

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 @@ -166,4 +166,13 @@ describe('rebuild', function () {
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 ecd7f3d

Please sign in to comment.