red-agent linuxbox rails cat transcode patch diff --git activerecord l

 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
29
30
red-agent@linuxbox ~/rails $ cat transcode.patch
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..7a499c8 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,13 @@ module ActiveRecord
end
end
+ # Transcodes +:string+ or +:text+ to a correct encoding. Might be overriden in
+ # the adapter for custom behavior.
+ def transcode_text(value)
+ condition = defined?(Encoding.default_internal) && !Encoding.default_internal.nil?
+ condition ? value.encode(Encoding.default_internal) : value
+ end
+
protected
# '0.123456' -> 123456
# '1.123456' -> 123456