Skip to content

Commit

Permalink
force convert encoding in transaction method
Browse files Browse the repository at this point in the history
  • Loading branch information
machu committed Jun 13, 2010
1 parent 54bd9cc commit cd3a692
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions misc/lib/compatible.rb
Expand Up @@ -47,8 +47,14 @@ def transaction(*args, &block)
compatible_transaction_original(*args, &block)
rescue PStoreRuby18Exception => e
# first loaded the pstore file (it's created by Ruby-1.8)
# force convert ASCII_8BIT pstore data to UTF_8
file = open_and_lock_file(@filename, false)
table = Marshal::load(file)
table = Marshal::load(file, proc {|obj|
if obj.respond_to?('force_encoding') && obj.encoding == Encoding::ASCII_8BIT
obj.force_encoding('UTF-8')
end
obj
})
table[:__ruby_version] = RUBY_VERSION
if on_windows?
save_data_with_fast_strategy(Marshal::dump(table), file)
Expand All @@ -59,22 +65,12 @@ def transaction(*args, &block)
end
end

# (1) force convert ASCII_8BIT pstore data if @force_convert_8bit_data == true
# (2) raise PStoreRuby18Exception if not found __ruby_version
private
def load(content)
table = Marshal::load(content)
if !table[:__ruby_version] || table[:__ruby_version] < '1.9'
if !table[:__ruby_version] || table[:__ruby_version] < RUBY_VERSION
raise PStoreRuby18Exception.new
else
# only convert ASCII_8BIT to UTF_8
load_proc = proc {|obj|
if obj.respond_to?('force_encoding') && obj.encoding == Encoding::ASCII_8BIT
obj.force_encoding('UTF-8')
end
obj
}
table = Marshal::load(content, load_proc)
# hide __ruby_version to caller
table.delete(:__ruby_version)
end
Expand Down

0 comments on commit cd3a692

Please sign in to comment.