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

fix: Allow option values containing quotation marks to be selected #29214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidfurey Only if you have the spare cycles - but I'm curious as a RegEx noob what this logic actually does and how it resolves the bug. Would appreciate an explanation (but again, only if you have time). Thank you!

notAllUniqueValues = true
}
}
Expand Down