Skip to content

Commit

Permalink
fix cy.contains.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Mar 21, 2022
1 parent e4f78a0 commit 44161a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/driver/cypress/fixtures/dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@

</div>

<div id="backslashes">"&lt;OE_D]dQ\</div>

<div id="wrapper">
<div id="upper">
<div class="item"><em>New</em> York</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,11 @@ describe('src/cy/commands/querying', () => {
cy.contains(/\'/)
})

// https://github.com/cypress-io/cypress/issues/19116
it('handles backslashes', () => {
cy.get('#backslashes').contains('"<OE_D]dQ\\')
})

describe('should(\'not.exist\')', () => {
it('returns null when no content exists', () => {
cy.contains('alksjdflkasjdflkajsdf').should('not.exist').then(($el) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/driver/src/dom/elements/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import $jquery from '../jquery'
import { getTagName } from './elementHelpers'
import { isWithinShadowRoot, getShadowElementFromPoint } from './shadow'
import { normalizeWhitespaces } from './utils'
import { escapeQuotes } from '../../util/escape'
import { escapeQuotes, escapeBackslashes } from '../../util/escape'

/**
* Find Parents relative to an initial element
Expand Down Expand Up @@ -229,7 +229,9 @@ export const getContainsSelector = (text, filter = '', options: {
} = {}) => {
const $expr = $.expr[':']

const escapedText = escapeQuotes(text)
const escapedText = escapeQuotes(
escapeBackslashes(text),
)

// they may have written the filter as
// comma separated dom els, so we want to search all
Expand Down

0 comments on commit 44161a9

Please sign in to comment.