Skip to content

Commit

Permalink
Fix and test for bug #1457 (Uncaught SyntaxError: Regular expression …
Browse files Browse the repository at this point in the history
…too large)

 - see test case which is extracted from a real world css file; the selector regex was able to traverse the curly brace as when looking for quotes, it wasn't taking into account that the start quote could be escaped
  • Loading branch information
eoghanmurray committed May 20, 2024
1 parent 03b5216 commit 557eddd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
}

// Use match logic from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const m = match(/^(("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^{])+)/);
const m = match(/^(((?<!\\)"(?:\\"|[^"])*"|(?<!\\)'(?:\\'|[^'])*'|[^{])+)/);
if (!m) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/rrweb-snapshot/test/rebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,14 @@ ul li.specified c:hover img, ul li.specified c.\\:hover img {
expect(getDuration(cachedEnd) * factor).toBeLessThan(getDuration(end));
});
});

it('should not incorrectly interpret escaped quotes', () => {
// the ':hover' in the below is a decoy which is not part of the selector,
// previously that part was being incorrectly consumed by the selector regex
const should_not_modify =
".tailwind :is(.before\\:content-\\[\\'\\'\\])::before { --tw-content: \":hover\"; content: var(--tw-content); }.tailwind :is(.\\[\\&\\>li\\]\\:before\\:content-\\[\\'-\\'\\] > li)::before { color: pink; }";
expect(adaptCssForReplay(should_not_modify, cache)).toEqual(
should_not_modify,
);
});
});

0 comments on commit 557eddd

Please sign in to comment.