Skip to content

Commit

Permalink
No neg lookbehind (#1493)
Browse files Browse the repository at this point in the history
* Older versions of Safari 16 don't support lookbehind assertions - https://caniuse.com/js-regexp-lookbehind

* Refactor to show the similarity between these two regexes

* Apply formatting changes

* Create no-neg-lookbehind.md

---------

Co-authored-by: eoghanmurray <eoghanmurray@users.noreply.github.com>
  • Loading branch information
eoghanmurray and eoghanmurray authored Jun 5, 2024
1 parent f3cf092 commit 82f6fec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/no-neg-lookbehind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"rrweb-snapshot": patch
"rrweb": patch
---

Replay: Replace negative lookbehind in regexes from css parser as it causes issues with Safari 16
2 changes: 1 addition & 1 deletion .changeset/silent-plants-perform.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'rrweb': patch
"rrweb": patch
---

Return early for child same origin frames
18 changes: 14 additions & 4 deletions packages/rrweb-snapshot/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
* Parse selector.
*/

// originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
const selectorMatcher = new RegExp(
'^((' +
[
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^{]',
].join('|') +
')+)',
);

function selector() {
whitespace();
while (css[0] == '}') {
Expand All @@ -432,8 +443,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
whitespace();
}

// 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(selectorMatcher);
if (!m) {
return;
}
Expand Down Expand Up @@ -869,8 +879,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
name +
'\\s*((?:' +
[
'(?<!\\\\)"(?:\\\\"|[^"])*"',
"(?<!\\\\)'(?:\\\\'|[^'])*'",
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
'[^;]',
].join('|') +
')+);',
Expand Down

0 comments on commit 82f6fec

Please sign in to comment.