Skip to content

Commit 82f6fec

Browse files
authored
No neg lookbehind (#1493)
* 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 <[email protected]>
1 parent f3cf092 commit 82f6fec

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.changeset/no-neg-lookbehind.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"rrweb-snapshot": patch
3+
"rrweb": patch
4+
---
5+
6+
Replay: Replace negative lookbehind in regexes from css parser as it causes issues with Safari 16

.changeset/silent-plants-perform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'rrweb': patch
2+
"rrweb": patch
33
---
44

55
Return early for child same origin frames

packages/rrweb-snapshot/src/css.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
424424
* Parse selector.
425425
*/
426426

427+
// originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
428+
const selectorMatcher = new RegExp(
429+
'^((' +
430+
[
431+
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
432+
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
433+
'[^{]',
434+
].join('|') +
435+
')+)',
436+
);
437+
427438
function selector() {
428439
whitespace();
429440
while (css[0] == '}') {
@@ -432,8 +443,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
432443
whitespace();
433444
}
434445

435-
// Use match logic from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1
436-
const m = match(/^(((?<!\\)"(?:\\"|[^"])*"|(?<!\\)'(?:\\'|[^'])*'|[^{])+)/);
446+
const m = match(selectorMatcher);
437447
if (!m) {
438448
return;
439449
}
@@ -869,8 +879,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet {
869879
name +
870880
'\\s*((?:' +
871881
[
872-
'(?<!\\\\)"(?:\\\\"|[^"])*"',
873-
"(?<!\\\\)'(?:\\\\'|[^'])*'",
882+
/[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped)
883+
/[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes
874884
'[^;]',
875885
].join('|') +
876886
')+);',

0 commit comments

Comments
 (0)