Skip to content

Commit 4331ee8

Browse files
authored
Merge pull request rails#27076 from y-yagi/fix_postgresql_array_encoding
use `force_encoding` instread of `encode!` to avoid `UndefinedConversionError`
2 parents 07af54d + 70878b6 commit 4331ee8

File tree

2 files changed

+4
-4
lines changed
  • activerecord

2 files changed

+4
-4
lines changed

activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def serialize(value)
3535
if value.is_a?(::Array)
3636
result = @pg_encoder.encode(type_cast_array(value, :serialize))
3737
if encoding = determine_encoding_of_strings(value)
38-
result.encode!(encoding)
38+
result.force_encoding(encoding)
3939
end
4040
result
4141
else

activerecord/test/cases/adapters/postgresql/array_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ def self.model_name; ActiveModel::Name.new(PgArray) end
312312
end
313313

314314
def test_encoding_arrays_of_utf8_strings
315-
string_with_utf8 = "nový"
316-
assert_equal [string_with_utf8], @type.deserialize(@type.serialize([string_with_utf8]))
317-
assert_equal [[string_with_utf8]], @type.deserialize(@type.serialize([[string_with_utf8]]))
315+
arrays_of_utf8_strings = %w(nový ファイル)
316+
assert_equal arrays_of_utf8_strings, @type.deserialize(@type.serialize(arrays_of_utf8_strings))
317+
assert_equal [arrays_of_utf8_strings], @type.deserialize(@type.serialize([arrays_of_utf8_strings]))
318318
end
319319

320320
private

0 commit comments

Comments
 (0)