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

fix: Update regex for formatting assertion messages to avoid catastrophic backtracking #29353

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Apr 18, 2024

Additional details

This fixes a regression that was introduced in #29243. Those changes can result in catastrophic backtracking when trying to match long assertion messages via the new Regex.

Additionally, I did restructure some of the code so that if certain conditions are not met where the message does not need to be run through the regex, it is no longer run through the regex. This should improve performance for some commands that were needlessly going through the regex check.

Steps to test

Run this repo with 13.7.3 and run it with this branch. The test should now pass in this branch.

I tried to write a test to ensure Cypress does not hang, but my test seems unpredictable. I haven't figured out the exact size of the assertion of content that will cause it to hang before and not after (without it being a complicated test including the plugin). I intend to followup with a PR to test this and am favoring getting this out quickly.

How has the user experience changed?

Before

Screenshot 2024-04-18 at 12 48 03 PM

After

Screenshot 2024-04-18 at 12 46 23 PM

PR Tasks

@jennifer-shehane jennifer-shehane self-assigned this Apr 18, 2024
@AtofStryker AtofStryker self-requested a review April 18, 2024 16:50
@jennifer-shehane jennifer-shehane changed the title fix: Revert addition of .* into regex and reformat code to escape early before regex runs fix: Update regex for formatting assertion messages to avoid catastrophic backtracking Apr 18, 2024
Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a regression test for what caused the issue in the first place by asserting on the Base64 encoded image?

@jennifer-shehane
Copy link
Member Author

@AtofStryker Yah, I'm trying to do that. It's kind of hard to find a test case in the goldilocks zone that fixes it but doesn't make a really long test. I'm about to try to replicate exactly what the plugin does as a test.

@jennifer-shehane
Copy link
Member Author

Concerned that a test could be performant on my Mac, but then hang on CI. It seems very specific to a certain size of string where it starts hanging. I opened a PR to add a test at some point: #29356

Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since performance testing base64 is somewhat difficult, we are going to create an issue to add a regression test and continue with merging the revision.

@jennifer-shehane jennifer-shehane merged commit 9b0abdd into develop Apr 18, 2024
82 of 84 checks passed
@jennifer-shehane jennifer-shehane deleted the revert-pr-29243 branch April 18, 2024 19:14
Copy link

cypress bot commented Apr 18, 2024

Passing run #55011 ↗︎

0 550 9 0 Flakiness 0

Details:

changelog update
Project: cypress Commit: 881d3d299c
Status: Passed Duration: 14:04 💡
Started: Apr 18, 2024 7:01 PM Ended: Apr 18, 2024 7:16 PM

Review all test suite changes for PR #29353 ↗︎

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 18, 2024

Released in 13.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.8.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress gets stuck in failing visual regression test after upgrading to 13.7.3
3 participants