Skip to content

Commit

Permalink
Escape quotation marks in option value query so that option values co…
Browse files Browse the repository at this point in the history
…ntaining quotation marks can be selected
  • Loading branch information
davidfurey committed Mar 28, 2024
1 parent 11c6dd8 commit 04f6331
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/driver/cypress/e2e/commands/actions/select.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ describe('src/cy/commands/actions/select', () => {
})
})

it('can select by value when value contains a quotation mark', () => {
cy.$$('select[name=maps] option:nth-child(3)').attr('value', '"test"')

cy.get('select[name=maps]').select('"test"').then(($select) => {
expect($select[0].selectedOptions[0].text).to.eq('nuke')
})
})

it('can select by index when value contains a quotation mark', () => {
cy.$$('select[name=maps] option:nth-child(3)').attr('value', '"test"')

cy.get('select[name=maps]').select(2).then(($select) => {
expect($select[0].selectedOptions[0].text).to.eq('nuke')
})
})

it('can handle index when all values are identical', () => {
cy.$$('select[name=maps] option').attr('value', 'foo')

Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/actions/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default (Commands, Cypress, cy) => {
values.push(value)

// https://github.com/cypress-io/cypress/issues/24739
if (options.$el.find(`option[value="${value}"]`).length > 1) {
if (options.$el.find(`option[value="${value.replace(/"/g, '\\\"')}"]`).length > 1) {
notAllUniqueValues = true
}
}
Expand Down

0 comments on commit 04f6331

Please sign in to comment.