aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/oid
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2018-06-03 12:23:15 +0200
committerLars Kanis <lars@greiz-reinsdorf.de>2018-06-23 18:59:45 +0200
commit6c46aad3f5edce30e009bd89d0a11dc3d95ffa93 (patch)
tree41ad9934abaeb89d418e5839edbcce51ab79f569 /activerecord/lib/active_record/connection_adapters/postgresql/oid
parent8d5c71ee7f3baf0f05d05d62bbc16ce13bc4679e (diff)
downloadrails-6c46aad3f5edce30e009bd89d0a11dc3d95ffa93.tar.gz
rails-6c46aad3f5edce30e009bd89d0a11dc3d95ffa93.tar.bz2
rails-6c46aad3f5edce30e009bd89d0a11dc3d95ffa93.zip
Return empty array when casting malformed array strings
Parsing of malformed array strings without raising an error is deprecated in pg-1.1. It's therefore necessary to catch parser errors starting with pg-2.0. See also pg commit: https://bitbucket.org/ged/ruby-pg/commits/1b081326b346368e70c9c03ee7080e28d6b3a3dc
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
index 26abeea7ed..6fbeaa2b9e 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb
@@ -33,7 +33,13 @@ module ActiveRecord
def cast(value)
if value.is_a?(::String)
- value = @pg_decoder.decode(value)
+ value = begin
+ @pg_decoder.decode(value)
+ rescue TypeError
+ # malformed array string is treated as [], will raise in PG 2.0 gem
+ # this keeps a consistent implementation
+ []
+ end
end
type_cast_array(value, :cast)
end