Skip to content
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
2 changes: 1 addition & 1 deletion lib/capybara/rack_test/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def set_input(value) # rubocop:disable Naming/AccessorMethodName
native.remove
else
value.to_s.tap do |set_value|
if set_value.end_with?("\n") && form&.css('input, textarea')&.count
if set_value.end_with?("\n") && form&.css('input, textarea')&.count == 1
native['value'] = set_value.to_s.chop
Capybara::RackTest::Form.new(driver, form).submit(self)
else
Expand Down
6 changes: 6 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
@session.find(:css, '#single_input').set("my entry\n")
expect(extract_results(@session)['single_input']).to eq('my entry')
end

it 'should not submit single text input forms if ended with \n and has multiple values' do
@session.visit('/form')
@session.find(:css, '#two_input_1').set("my entry\n")
expect(@session.find(:css, '#two_input_1').value).to eq("my entry\n")
end
end

describe '#tag_name' do
Expand Down
5 changes: 5 additions & 0 deletions lib/capybara/spec/views/form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ New line after and before textarea tag
<input type="text" name="form[single_input]" id="single_input"/>
</form>

<form id="two_input_form" action="/form" method="post">
<input type="text" name="form[two_input_1]" id="two_input_1"/>
<input type="text" name="form[two_input_2]" id="two_input_2"/>
</form>

<label>Confusion
<input type="checkbox" id="confusion_checkbox" class="confusion-checkbox confusion"/>
</label>
Expand Down