Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amp 99342 regex error #16

Merged
merged 8 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions 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 Expand Up @@ -854,7 +854,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
19 changes: 19 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,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,
);
});
});
Loading