diff --git a/lib/capybara/rack_test/form.rb b/lib/capybara/rack_test/form.rb index 863610b9..fa291039 100644 --- a/lib/capybara/rack_test/form.rb +++ b/lib/capybara/rack_test/form.rb @@ -120,7 +120,7 @@ private end def add_textarea_param(field, params) - merge_param!(params, field['name'], field['_capybara_raw_value'].to_s.gsub(/\n/, "\r\n")) + merge_param!(params, field['name'], field['_capybara_raw_value'].to_s.gsub(/\r?\n/, "\r\n")) end def submitter?(el) diff --git a/lib/capybara/spec/session/fill_in_spec.rb b/lib/capybara/spec/session/fill_in_spec.rb index e753bef4..d56074b6 100644 --- a/lib/capybara/spec/session/fill_in_spec.rb +++ b/lib/capybara/spec/session/fill_in_spec.rb @@ -98,6 +98,12 @@ Capybara::SpecHelper.spec '#fill_in' do expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n") end + it 'should handle carriage returns with line feeds in a textarea correct' do + @session.fill_in('form_description', with: "\r\nSome text\r\n") + @session.click_button('awesome') + expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n") + end + it 'should fill in a color field' do @session.fill_in('Html5 Color', with: '#112233') @session.click_button('html5_submit')