From b8d65a01fe6796f71c794c47d36d17bae3853967 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 24 Sep 2015 16:01:30 +0200 Subject: [PATCH] .trim() all form params from now. --- .../_application_controller_form.js.coffee | 4 +- app/views/tests/form_trim.html.erb | 37 +++++++++++++++++++ config/routes/test.rb | 1 + public/assets/tests/form-trim.js | 28 ++++++++++++++ test/browser/aab_unit_test.rb | 6 +++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 app/views/tests/form_trim.html.erb create mode 100644 public/assets/tests/form-trim.js diff --git a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee index 41636071f..aca9cee32 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_form.js.coffee @@ -450,11 +450,11 @@ class App.ControllerForm extends App.Controller # collect all params, push it to an array if already exists if param[key.name] isnt undefined if typeof param[key.name] is 'string' - param[key.name] = [param[key.name], key.value] + param[key.name] = [param[key.name], key.value.trim()] else param[key.name].push key.value else - param[key.name] = key.value + param[key.name] = key.value.trim() # data type conversion for key of param diff --git a/app/views/tests/form_trim.html.erb b/app/views/tests/form_trim.html.erb new file mode 100644 index 000000000..e81d806f0 --- /dev/null +++ b/app/views/tests/form_trim.html.erb @@ -0,0 +1,37 @@ + + + + + + + + + +
+ +
+
+ + + + + + + + + +
lala
+
la +la
+
+
diff --git a/config/routes/test.rb b/config/routes/test.rb index 6bbbfdde7..19ec957e3 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -5,6 +5,7 @@ Zammad::Application.routes.draw do match '/tests-model', to: 'tests#model', via: :get match '/tests-model-ui', to: 'tests#model_ui', via: :get match '/tests-form', to: 'tests#form', via: :get + match '/tests-form-trim', to: 'tests#form_trim', via: :get match '/tests-form-extended', to: 'tests#form_extended', via: :get match '/tests-form-validation', to: 'tests#form_validation', via: :get match '/tests-table', to: 'tests#table', via: :get diff --git a/public/assets/tests/form-trim.js b/public/assets/tests/form-trim.js new file mode 100644 index 000000000..9a8e73d76 --- /dev/null +++ b/public/assets/tests/form-trim.js @@ -0,0 +1,28 @@ + +test( 'form trim checks', function() { + + var el = $('#form1') + var test_params = { + input1: '', + input2: '', + input3: 'a', + input4: 'a b', + input5: 'äö ü', + textarea1: '', + textarea2: '', + textarea3: 'a', + textarea4: "test\r\n\r\n 123", + ce1: 'lala', + ce2: "la\nla", + } + + el.find('[contenteditable]').ce({ + mode: 'richtext' + }) + + var params = App.ControllerForm.params( el ) + + deepEqual( params, test_params, 'form param check' ) + console.log('22', params) + console.log('22', test_params) +}) diff --git a/test/browser/aab_unit_test.rb b/test/browser/aab_unit_test.rb index 866f4818c..6b11065cd 100644 --- a/test/browser/aab_unit_test.rb +++ b/test/browser/aab_unit_test.rb @@ -45,6 +45,12 @@ class AAbUnitTest < TestCase value: '0', ) + location( url: browser_url + '/tests-form-trim' ) + match( + css: '.result .failed', + value: '0', + ) + location( url: browser_url + '/tests-form-extended' ) sleep 8 match(