diff --git a/.changeset/fair-ducks-clean.md b/.changeset/fair-ducks-clean.md new file mode 100644 index 0000000000..3f65a2b8bc --- /dev/null +++ b/.changeset/fair-ducks-clean.md @@ -0,0 +1,5 @@ +--- +'@amplitude/rrweb': patch +--- + +Fix and test for bug #1457 which was affecting replay of complex tailwind css diff --git a/packages/rrweb-snapshot/src/css.ts b/packages/rrweb-snapshot/src/css.ts index 4645deae4f..d609a972f6 100644 --- a/packages/rrweb-snapshot/src/css.ts +++ b/packages/rrweb-snapshot/src/css.ts @@ -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(/^(((? { const pos = position(); const m = match(re); diff --git a/packages/rrweb-snapshot/test/rebuild.test.ts b/packages/rrweb-snapshot/test/rebuild.test.ts index 097ff0989a..5d544ccfa7 100644 --- a/packages/rrweb-snapshot/test/rebuild.test.ts +++ b/packages/rrweb-snapshot/test/rebuild.test.ts @@ -203,4 +203,23 @@ 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, + ); + }); + + 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, + ); + }); });