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

better splitting of selectors #1440

Merged
merged 17 commits into from
Apr 18, 2024
Merged

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Apr 9, 2024

As part of the full investigation in PostHog/posthog#21427 I noticed that nested commas in selectors are not very well supported by the current .split regex.

Moved to a JS function that only splits root selectors with a comma.

It looks to me like the css.parse is only used to generate this AST in one place. Perhaps it's better we move this whole function over to use the already included cssom equivalent method. Unsure if that suffers the same issues, so proposing this given I know it works but happy to explore the alternative root if it is preferred.

@eoghanmurray might be best placed to help here given recent work on hover selectors

Copy link

changeset-bot bot commented Apr 9, 2024

🦋 Changeset detected

Latest commit: fb91382

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
rrweb-snapshot Patch
rrweb Patch
rrdom Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/types Patch
@rrweb/web-extension Patch
rrvideo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@eoghanmurray
Copy link
Contributor

This is great, I suggest you create a bug report or PR on the codebase that css.ts was copied from; https://github.com/reworkcss/css/blob/master/lib/parse/index.js

@eoghanmurray
Copy link
Contributor

Unfortunately I was able to produce a further failing test by being pathological:

li[attr="weirdly("] a:hover, li[attr="weirdly)"] a {}

84f0f22

This PR is better than what we had before, but do you want to improve further to fix my test case?

@daibhin
Copy link
Contributor Author

daibhin commented Apr 10, 2024

@eoghanmurray you piqued my nerd. Think the extra check to see if the selector is within an unclosed string should do the trick.

Looks like there is one failing test but I'm not sure that is related

@eoghanmurray
Copy link
Contributor

Tests needed a re-run after your latest commit this morning, but I managed to add another test case that breaks things;

it's possible to escape double quotes within those css strings :(

@daibhin daibhin requested a review from eoghanmurray April 10, 2024 18:19
@daibhin daibhin requested a review from eoghanmurray April 16, 2024 14:53
@daibhin
Copy link
Contributor Author

daibhin commented Apr 17, 2024

I'm not permitted to merge this PR so I'll leave it up to a library maintainer

@eoghanmurray
Copy link
Contributor

@daibhin I added a question above: "Was this removed accidentally?"

@daibhin
Copy link
Contributor Author

daibhin commented Apr 17, 2024

@eoghanmurray I couldn't find your latest question. Did you mean the final test case? I left a reply in #1440 (comment) that hopefully explains things

…trings' - I needed to escape the backslash to demonstrate the test case
 - the added test case didn't actually fail before due to some voodoo with `m.replace(/,/g, '\u200C');` which took me ages to figure out.  Anyhow I figure test and refactor is good in case we replace the css library
@eoghanmurray
Copy link
Contributor

I've just noticed #1401 which has been merged into trunk and seems to solve a similar issue; I'll try to run the new tests from this PR against master now...

@eoghanmurray
Copy link
Contributor

trickresult test still fails on master ... so we still need this PR!
The merge is not straightforward though...

@eoghanmurray
Copy link
Contributor

eoghanmurray commented Apr 18, 2024

I've added back the weirderresult test again btw and tweaked it so that escaping was effective to demonstrate the problem

Also added another test which wasn't failing, but which 'could have been' if not for some luck elsewhere! See 4091fbd for details

update changeset to reflect more limited effect
@eoghanmurray eoghanmurray merged commit c0f83af into rrweb-io:master Apr 18, 2024
6 checks passed
@daibhin daibhin deleted the fix/css-selectors branch April 19, 2024 09:26
billyvg pushed a commit to getsentry/rrweb that referenced this pull request Apr 19, 2024
* better splitting of selectors - overlapping with rrweb-io#1401
* Add test from example at PostHog/posthog#21427
* ignore brackets inside selector strings
* Add another test as noticed that it's possible to escape strings
* Ensure we are ignoring commas within strings

Co-authored-by: Eoghan Murray <[email protected]>
billyvg pushed a commit to getsentry/rrweb that referenced this pull request Apr 19, 2024
* better splitting of selectors - overlapping with rrweb-io#1401
* Add test from example at PostHog/posthog#21427
* ignore brackets inside selector strings
* Add another test as noticed that it's possible to escape strings
* Ensure we are ignoring commas within strings

Co-authored-by: Eoghan Murray <[email protected]>
billyvg pushed a commit to getsentry/rrweb that referenced this pull request Apr 19, 2024
* better splitting of selectors - overlapping with rrweb-io#1401 
* Add test from example at PostHog/posthog#21427
* ignore brackets inside selector strings
* Add another test as noticed that it's possible to escape strings
* Ensure we are ignoring commas within strings

Co-authored-by: Eoghan Murray <[email protected]>
billyvg added a commit to getsentry/rrweb that referenced this pull request Apr 19, 2024
#169)" (#182)

This reverts commit 810b39f.


Reverting this in favor of rrweb-io#1401
and rrweb-io#1440 which is better than
whatever it is I wrote. I kept our tests just to ensure the fix is
compatible with our previous patch.
jaj1014 pushed a commit to pendo-io/rrweb that referenced this pull request Apr 30, 2024
* better splitting of selectors - overlapping with rrweb-io#1401
* Add test from example at PostHog/posthog#21427
* ignore brackets inside selector strings
* Add another test as noticed that it's possible to escape strings
* Ensure we are ignoring commas within strings

Co-authored-by: Eoghan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants