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

Unrecognized expression for regex that ends with /=\s+[0-6]/ #21108

Closed
asartalo opened this issue Apr 17, 2022 · 5 comments · Fixed by #21388
Closed

Unrecognized expression for regex that ends with /=\s+[0-6]/ #21108

asartalo opened this issue Apr 17, 2022 · 5 comments · Fixed by #21388
Labels
pkg/driver This is due to an issue in the packages/driver directory Reproducible Can be reproduced type: bug

Comments

@asartalo
Copy link

Current behavior

I have a cy.contains() call with the following:

cy.contains(/[56]\s+-\s+[0-6]\s+=\s+[0-6]/);

And it fails with:

Error: Syntax error, unrecognized expression: :cy-contains('/[56]\s+-\s+[0-6]\s+='\s+[0-6']/'), [type='submit'][value~='/[56]\s+-\s+[0-6]\s+='\s+[0-6']/']

It looks like there are extra single quotes? I'm not sure. The minimal code that throws the same error is:

cy.contains(/=\s+[0-6]/);

Desired behavior

Should not throw Error "Syntax error, unrecognized expression".

Test code to reproduce

https://github.com/asartalo/cypress-test-cy-contains-fail

Cypress Version

9.5.4

Other

No response

@davidmunechika
Copy link
Contributor

davidmunechika commented Apr 18, 2022

Thanks for opening an issue! I was able to reproduce this issue and it does appear to be a bug in how we are handling RegEx. It also seemed to fail with cy.contains(/=[0-6]/);

Screenshot 2022-04-18 at 11 10 10 AM

@davidmunechika davidmunechika added type: bug pkg/driver This is due to an issue in the packages/driver directory labels Apr 18, 2022
@sainthkh
Copy link
Contributor

sainthkh commented Apr 19, 2022

I tested with the code below.

<div>a=2</div>
<div>a</div>
<div>b</div>
<div>5 - 6 = 6</div>
it('t', () => {
  cy.visit('fixtures/a.html')
  cy.contains(/=[0-6]/).should('have.text', 'a=2')
  cy.contains(/[56]\s+-\s+[0-6]\s+=\s+[0-6]/)
})

It's working when there is text to find with = sign.

But when there is no element with =. it doesn't wait for it to appear, but to throw an error with the error message above.

@sainthkh sainthkh added stage: awaiting response Potential fix was proposed; awaiting response and removed stage: awaiting response Potential fix was proposed; awaiting response labels Apr 19, 2022
@sainthkh
Copy link
Contributor

At first, I thought the bug was about cy.contains() not working correctly. But it was showing wrong error message.

The problem is a bit hard to fix because Sizzle escapes attribute selector in the code below:

https://github.com/jquery/sizzle/blob/20390f05731af380833b5aa805db97de0b91268a/external/jquery/jquery.js#L4363-L4370

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 18, 2022

The code for this is done in cypress-io/cypress#21388, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label May 18, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 23, 2022

Released in 9.7.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory Reproducible Can be reproduced type: bug
Projects
None yet
3 participants