diff options
author | Mauricio Linhares <mauricio.linhares@gmail.com> | 2014-02-01 01:11:03 -0300 |
---|---|---|
committer | Mauricio Linhares <mauricio.linhares@gmail.com> | 2014-02-01 09:38:43 -0300 |
commit | a34c10f73e739142794a2e6366328051fcc91238 (patch) | |
tree | f9a8d762068a351c1a00bf422ac56cdfb689ffe3 /activerecord | |
parent | 9b2a017aa82f95911280ed597e4bf3193c9399e9 (diff) | |
download | rails-a34c10f73e739142794a2e6366328051fcc91238.tar.gz rails-a34c10f73e739142794a2e6366328051fcc91238.tar.bz2 rails-a34c10f73e739142794a2e6366328051fcc91238.zip |
Fixes issue with parsing whitespace content back from database - fixes #13907
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 12 |
3 files changed, 26 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 8c09284e53..22f86fb2e1 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,14 @@ +* Parsing PostgreSQL arrays with empty strings now works correctly. + + Previously, if you tried to parse `{"1","","2","","3"}` the result + would be `["1","2","3"]`, removing the empty strings from the array, + which would be incorrect. Now it will correctly produce `["1","","2","","3"]` + as the result of parsing the above PostgreSQL array. + + Fixes #13907. + + *MaurĂcio Linhares* + * Associations now raise `ArgumentError` on name conflicts. Dangerous association names conflicts include instance or class methods already diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb b/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb index 20de8d1982..0b218f2bfd 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/array_parser.rb @@ -91,8 +91,9 @@ module ActiveRecord end def add_item_to_array(array, current_item, quoted) - if current_item.length == 0 - elsif !quoted && current_item == 'NULL' + return if !quoted && current_item.length == 0 + + if !quoted && current_item == 'NULL' array.push nil else array.push current_item diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index d71e2aa2bb..3090f4478f 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -93,6 +93,18 @@ class PostgresqlArrayTest < ActiveRecord::TestCase assert_cycle(:tags, [[['1'], ['2']], [['2'], ['3']]]) end + def test_with_empty_strings + assert_cycle(:tags, [ '1', '2', '', '4', '', '5' ]) + end + + def test_with_multi_dimensional_empty_strings + assert_cycle(:tags, [[['1', '2'], ['', '4'], ['', '5']]]) + end + + def test_with_arbitrary_whitespace + assert_cycle(:tags, [[['1', '2'], [' ', '4'], [' ', '5']]]) + end + def test_multi_dimensional_with_integers assert_cycle(:ratings, [[[1], [7]], [[8], [10]]]) end |