diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-11-06 10:36:56 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-11-06 10:40:00 +0000 |
commit | fc988115f75bdca6aa95454208b49125a5041117 (patch) | |
tree | 0c3af795a4459a6a80b29f419393e8d47121b417 /actionpack/lib | |
parent | 7776055e2dcd29e0f8f27154663263c0bbd1c188 (diff) | |
download | rails-fc988115f75bdca6aa95454208b49125a5041117.tar.gz rails-fc988115f75bdca6aa95454208b49125a5041117.tar.bz2 rails-fc988115f75bdca6aa95454208b49125a5041117.zip |
Implement a workaround for a bug in ruby-1.9.3p0.
The bug is that an error would be raised while attempting to convert a
template from one encoding to another.
Please see http://redmine.ruby-lang.org/issues/5564 for more details.
The workaround is to load all conversions into memory ahead of time,
and will only happen if the ruby version is *exactly* 1.9.3p0. The
hope is obviously that the underlying problem will be resolved in
the next patchlevel release of 1.9.3.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/data/encoding_conversions.dump | bin | 0 -> 122854 bytes | |||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 26 |
2 files changed, 26 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/data/encoding_conversions.dump b/actionpack/lib/action_view/data/encoding_conversions.dump Binary files differnew file mode 100644 index 0000000000..18d7cd448b --- /dev/null +++ b/actionpack/lib/action_view/data/encoding_conversions.dump diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 10797c010f..1f1a8f7867 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -3,6 +3,32 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/try' require 'active_support/core_ext/kernel/singleton_class' +if RUBY_ENGINE == 'ruby' && RUBY_VERSION == '1.9.3' && RUBY_PATCHLEVEL == 0 + # This is a hack to work around a bug in Ruby 1.9.3p0: + # http://redmine.ruby-lang.org/issues/5564 + # + # Basically, at runtime we may need to perform some encoding conversions on the templates, + # but if the converter hasn't been loaded by Ruby beforehand (i.e. now), then it won't be + # able to find it (due to a bug). + # + # However, we don't know what conversions we may need to do a runtime. So we load up a + # marshal-dumped structure which contains a pre-generated list of all the possible conversions, + # and we load all of them. + # + # In my testing this increased the process size by about 3.9 MB (after the conversions array + # is GC'd) and took around 170ms to run, which seems acceptable for a workaround. + # + # The script to dump the conversions is: https://gist.github.com/1342729 + + filename = File.join(File.dirname(__FILE__), 'data', 'encoding_conversions.dump') + conversions = Marshal.load(File.read(filename)) + conversions.each do |from, to_array| + to_array.each do |to| + Encoding::Converter.new(from, to) + end + end +end + module ActionView # = Action View Template class Template |