From cf1234ef386c2fb90a0bef3de80f79881f8829ec Mon Sep 17 00:00:00 2001 From: David Newell Date: Tue, 9 Apr 2024 11:25:52 +0100 Subject: [PATCH] fix: nested css selector splitting (#21427) --- patches/rrweb@2.0.0-alpha.12.patch | 48 ++++++++++++++++++++++++++++++ pnpm-lock.yaml | 6 ++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/patches/rrweb@2.0.0-alpha.12.patch b/patches/rrweb@2.0.0-alpha.12.patch index 80574ce4eb..e3fe50fb9a 100644 --- a/patches/rrweb@2.0.0-alpha.12.patch +++ b/patches/rrweb@2.0.0-alpha.12.patch @@ -520,3 +520,51 @@ index e9a8ab2ba94093198f3dc42c9f6c4915f99cbc1d..182662fff8cca2eb4c63d956f0fce946 } } applyMutation(d, isSync) { +diff --git a/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js b/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +index 342e1df171368d312dc0372dace0c6b5a1eb9c61..e98368347aab6f22902e691e1909aa0333232140 100644 +--- a/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js ++++ b/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js +@@ -1254,16 +1254,40 @@ function parse(css, options = {}) { + if (!m) { + return; + } +- return trim(m[0]) ++ return splitRootSelectors(trim(m[0]) + .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '') + .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, (m) => { + return m.replace(/,/g, '\u200C'); +- }) +- .split(/\s*(?![^(]*\)),\s*/) ++ })) + .map((s) => { + return s.replace(/\u200C/g, ','); + }); + } ++ function splitRootSelectors(input) { ++ let parts = []; ++ let nestedLevel = 0; ++ let currentPart = ''; ++ ++ for (let i = 0; i < input.length; i++) { ++ const char = input[i]; ++ currentPart += char; ++ ++ if (char === '(') { ++ nestedLevel++; ++ } else if (char === ')') { ++ nestedLevel--; ++ } else if (char === ',' && nestedLevel === 0) { ++ parts.push(currentPart.slice(0, -1).trim()); ++ currentPart = ''; ++ } ++ } ++ ++ if (currentPart.trim() !== '') { ++ parts.push(currentPart.trim()); ++ } ++ ++ return parts; ++ } + function declaration() { + const pos = position(); + const propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 36eee7a33b..b619d3894a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,7 +9,7 @@ overrides: patchedDependencies: rrweb@2.0.0-alpha.12: - hash: 2rbzexnjhaf34oglgkdlfbhwde + hash: t3xxecww6aodjl4qopwv6jdxmq path: patches/rrweb@2.0.0-alpha.12.patch dependencies: @@ -327,7 +327,7 @@ dependencies: version: 1.5.1 rrweb: specifier: 2.0.0-alpha.12 - version: 2.0.0-alpha.12(patch_hash=2rbzexnjhaf34oglgkdlfbhwde) + version: 2.0.0-alpha.12(patch_hash=t3xxecww6aodjl4qopwv6jdxmq) sass: specifier: ^1.26.2 version: 1.56.0 @@ -19160,7 +19160,7 @@ packages: resolution: {integrity: sha512-i4sz9469dbsEGFiBzCkq+7I7M+imPeC3NrKgrrdJ2tXu9H+/eegNe4SrQgCsLBeSZHZDHU0o9L5rxTAiapWbGg==} dev: false - /rrweb@2.0.0-alpha.12(patch_hash=2rbzexnjhaf34oglgkdlfbhwde): + /rrweb@2.0.0-alpha.12(patch_hash=t3xxecww6aodjl4qopwv6jdxmq): resolution: {integrity: sha512-lUGwBV7gmbwz1dIgzo9EEayIVyxoTIF6NBF6+Jctqs4Uy45QkyARtikpQlCUfxVCGTCQ0FOee9jeVYsG39oq1g==} dependencies: '@rrweb/types': 2.0.0-alpha.12