From 6c46aad3f5edce30e009bd89d0a11dc3d95ffa93 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sun, 3 Jun 2018 12:23:15 +0200 Subject: 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 --- .../lib/active_record/connection_adapters/postgresql/oid/array.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid') 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 -- cgit v1.2.3