From 9122dd108fe12cd48d1be0b925d059b890488770 Mon Sep 17 00:00:00 2001 From: Stefan Hoffmann Date: Fri, 6 May 2022 15:51:15 +0200 Subject: [PATCH] Do not add additional carriage returns to CR+LF in textareas with rack_test --- lib/capybara/rack_test/form.rb | 2 +- lib/capybara/spec/session/fill_in_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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')