fix: ignore empty or nil keys in Node#send_keys#313
Open
myabc wants to merge 1 commit into
Open
Conversation
Ferrum raises ArgumentError on empty or nil keys, so
`send_keys("")` or `send_keys(nil)` crashes under Cuprite while the
Selenium and rack_test drivers treat them as a no-op. Reject empty and
nil entries before delegating to Ferrum so otherwise portable Capybara
code stays driver-agnostic.
db26711 to
d0f5829
Compare
There was a problem hiding this comment.
Pull request overview
This PR aligns Capybara::Cuprite::Node#send_keys behavior with Capybara’s Selenium and rack_test drivers by treating nil and empty-string key inputs as a no-op instead of raising, improving driver-agnostic test/code portability.
Changes:
- Filter out
niland""entries inNode#send_keys, and return early when no keys remain. - Add a feature spec asserting
send_keys("")andsend_keys(nil)do not raise and do not change the field value. - Document the behavior change in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/capybara/cuprite/node.rb |
Filters out nil/empty keys before delegating, avoiding Ferrum exceptions and no-op’ing when nothing remains. |
spec/features/driver_spec.rb |
Adds coverage ensuring empty/nil send_keys inputs do not raise and do not mutate the field. |
CHANGELOG.md |
Notes the fixed behavior for Node#send_keys in Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Node#send_keys
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Capybara::Cuprite::Node#send_keysraises on empty or nil keys, diverging from the Selenium and rack_test drivers which treat them as a no-op:send_keysforwards straight toFerrum::Keyboard#type, which rejects empty/nil input. This breaks otherwise driver-agnostic Capybara code such assend_keys(value)wherevaluemay be""— common when conditionally clearing or filling a field. Callers currently have to add their ownsend_keys(x) if xguards for Cuprite only.Real world example: https://github.com/citizensadvice/capybara_accessible_selectors/pull/157/changes#diff-8a7441fcb90a95d9647b64ef89630240641dfb8cd8d88ea3d4768d4053e8af5aR75
Fix
Reject
niland""entries before delegating to Ferrum, and no-op when nothing remains. Meaningful keys (including symbols like:enterand modifier chords like[:control, "a"]) pass through unchanged, and empty strings mixed with real keys are dropped rather than crashing.Testing
New spec in the "has ability to send keys" context asserts
send_keys("")andsend_keys(nil)do not raise and leave the field unchanged. Full send_keys context green (25 examples). Rubocop clean.