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

cy.contains will throw unrecognized expression error if it tries to match against regex containing single quotation mark #8626

Closed
LiChoi opened this issue Sep 19, 2020 · 3 comments · Fixed by #14311
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@LiChoi
Copy link

LiChoi commented Sep 19, 2020

Current behavior:

cy.contains will throw invalid expression error if you try to match a regex containing a quotation

Desired behavior:

cy.contains should be able to handle any valid regular expression

Test code to reproduce

cy.visit(any_url)
expect(/\'/.test(`'`)).to.be.true  // This test will pass, demonstrating that /\'/ is a valid regular expression 
cy.contains("div", /\'/).should('not.exist') // This will throw unrecognized expression error

Versions

Cypress 5.1.0
Mac OS Catalina
chrome 85

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Dec 18, 2020

I can recreate this issue in 6.1.0

Reproducible example

spec.js

it('test', () => {
  cy.contains(/\'/)
})
Syntax error, unrecognized expression: :not(script,style):cy-contains('/\'/'), [type='submit'][value~='/\'/']

    at Function.Sizzle.error (http://localhost:59685/__cypress/runner/cypress_runner.js:87720:9)
    at Sizzle.tokenize (http://localhost:59685/__cypress/runner/cypress_runner.js:88372:12)
    at Function.Sizzle [as find] (http://localhost:59685/__cypress/runner/cypress_runner.js:86994:16)
    at jQuery.fn.init.find (http://localhost:59685/__cypress/runner/cypress_runner.js:89055:12)
    at new jQuery.fn.init (http://localhost:59685/__cypress/runner/cypress_runner.js:89165:33)
    at Object.query (http://localhost:59685/__cypress/runner/cypress_runner.js:179962:11)
    at $Cy.$$ (http://localhost:59685/__cypress/runner/cypress_runner.js:169245:18)
    at getElements (http://localhost:59685/__cypress/runner/cypress_runner.js:158233:21)
From previous event:
    at resolveElements (http://localhost:59685/__cypress/runner/cypress_runner.js:158283:28)
    at $Cy.get (http://localhost:59685/__cypress/runner/cypress_runner.js:158294:15)
    at $Cy.now (http://localhost:59685/__cypress/runner/cypress_runner.js:170123:48)
    at resolveElements (http://localhost:59685/__cypress/runner/cypress_runner.js:158456:20)
From previous event:
    at Context.contains (http://localhost:59685/__cypress/runner/cypress_runner.js:158488:26)
    at Context.<anonymous> (http://localhost:59685/__cypress/runner/cypress_runner.js:170049:22)
    at <unknown> (http://localhost:59685/__cypress/runner/cypress_runner.js:169473:16)
From previous event:
    at runCommand (http://localhost:59685/__cypress/runner/cypress_runner.js:169452:9)
    at next (http://localhost:59685/__cypress/runner/cypress_runner.js:169598:15)
From previous event:
    at Promise.catch.err.name (http://localhost:59685/__cypress/runner/cypress_runner.js:169639:38)
From previous event:
    at run (http://localhost:59685/__cypress/runner/cypress_runner.js:169632:22)
    at $Cy.cy.<computed> [as contains] (http://localhost:59685/__cypress/runner/cypress_runner.js:170089:12)
    at Context.runnable.fn (http://localhost:59685/__cypress/runner/cypress_runner.js:170313:22)
    at callFn (http://localhost:59685/__cypress/runner/cypress_runner.js:104396:22)
    at Test.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (http://localhost:59685/__cypress/runner/cypress_runner.js:104383:8)
    at <unknown> (http://localhost:59685/__cypress/runner/cypress_runner.js:175865:29)
From previous event:
    at Object.onRunnableRun (http://localhost:59685/__cypress/runner/cypress_runner.js:175853:18)
    at $Cypress.action (http://localhost:59685/__cypress/runner/cypress_runner.js:166457:29)
    at Test.Runnable.run (http://localhost:59685/__cypress/runner/cypress_runner.js:174232:14)
    at Runner.../driver/node_modules/mocha/lib/runner.js.Runner.runTest (http://localhost:59685/__cypress/runner/cypress_runner.js:105055:11)
    at <unknown> (http://localhost:59685/__cypress/runner/cypress_runner.js:105181:13)
    at next (http://localhost:59685/__cypress/runner/cypress_runner.js:104964:15)
    at <unknown> (http://localhost:59685/__cypress/runner/cypress_runner.js:104974:8)
    at next (http://localhost:59685/__cypress/runner/cypress_runner.js:104876:15)
    at <unknown> (http://localhost:59685/__cypress/runner/cypress_runner.js:104942:6)
    at timeslice (http://localhost:59685/__cypress/runner/cypress_runner.js:98868:28)

Screen Shot 2020-12-18 at 8 34 43 AM

This is broke all the way back to 3.6.1, but the expression was different back then in the error:

Error: Syntax error, unrecognized expression: :not(script,style):contains('/\\'/'), [type='submit'][value~='/\\'/']

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Dec 18, 2020
@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Dec 18, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress labels Dec 24, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Dec 28, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 28, 2020

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

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 4, 2021

Released in 6.2.1.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 4, 2021
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 type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants