1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13912 from mauricio/bug-13907

Fixes issue with parsing whitespace content back from database - fixes #13907
This commit is contained in:
Rafael Mendonça França 2014-02-01 09:45:46 -08:00
commit 989923e5a4
3 changed files with 26 additions and 2 deletions

View file

@ -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. * Associations now raise `ArgumentError` on name conflicts.
Dangerous association names conflicts include instance or class methods already Dangerous association names conflicts include instance or class methods already

View file

@ -91,8 +91,9 @@ module ActiveRecord
end end
def add_item_to_array(array, current_item, quoted) def add_item_to_array(array, current_item, quoted)
if current_item.length == 0 return if !quoted && current_item.length == 0
elsif !quoted && current_item == 'NULL'
if !quoted && current_item == 'NULL'
array.push nil array.push nil
else else
array.push current_item array.push current_item

View file

@ -93,6 +93,18 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
assert_cycle(:tags, [[['1'], ['2']], [['2'], ['3']]]) assert_cycle(:tags, [[['1'], ['2']], [['2'], ['3']]])
end 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 def test_multi_dimensional_with_integers
assert_cycle(:ratings, [[[1], [7]], [[8], [10]]]) assert_cycle(:ratings, [[[1], [7]], [[8], [10]]])
end end