Skip to content

Commit

Permalink
fix: Escape quotation marks in option value query so that option valu…
Browse files Browse the repository at this point in the history
…es containing quotation marks can be selected
  • Loading branch information
davidfurey committed Mar 28, 2024
1 parent fb87950 commit ed91b9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _Released 4/2/2024 (PENDING)_

- Fixed an issue where Cypress was not executing beyond the first spec in `cypress run` for versions of Firefox 124 and up when a custom user agent was provided. Fixes [#29190](https://github.com/cypress-io/cypress/issues/29190).
- Fixed a bug where fields using arrays in `cypress.config` are not correctly processed. Fixes [#27103](https://github.com/cypress-io/cypress/issues/27103). Fixed in [#27312](https://github.com/cypress-io/cypress/pull/27312).
- Fixed a bug where option values containing quotation marks could not be selected. Fixes [#29213](https://github.com/cypress-io/cypress/issues/29213)

## 13.7.1

Expand Down
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 ed91b9d

Please sign in to comment.