diff --git activerecord lib active_record connection_adapters abstract

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index 520f3c8..296a155 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -67,8 +67,8 @@ module ActiveRecord
def type_cast(value)
return nil if value.nil?
case type
- when :string then value
- when :text then value
+ when :string then self.class.transcode_text(value)
+ when :text then self.class.transocde_text(value)
when :integer then value.to_i rescue value ? 1 : 0
when :float then value.to_f
when :decimal then self.class.value_to_decimal(value)
@@ -166,6 +166,12 @@ module ActiveRecord
end
end
+ # Transcodes +:string+ or +:text+ to a correct encoding.
+ def transcode_text(value)
+ condition = defined?(Encoding.default_internal) && !Encoding.default_internal.nil?
+ condition ? value.force_encoding(Encoding.default_internal) : value
+ end
+
protected
# '0.123456' -> 123456
# '1.123456' -> 123456