summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-01-28 04:58:11 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-01-28 04:58:11 +0000
commit24d73d4644650cb087f6d3a82f9f0536b65aad2a (patch)
treee3171357933e0bbffc10e2a62f28c986c2d5a6e7 /app
parent84e2822e27469c110821801f9dc2b81413392c5d (diff)
downloadredmine-24d73d4644650cb087f6d3a82f9f0536b65aad2a.tar.gz
redmine-24d73d4644650cb087f6d3a82f9f0536b65aad2a.zip
Ruby1.9: enforce UTF-8 encodings on the params hash on Rails2 (#4050, #4796)
Without this change, non ASCII subject issue cannot be created on Ruby 1.9. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8714 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 483dcf094..a0fa5c4af 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -43,6 +43,28 @@ class ApplicationController < ActionController::Base
end
end
+ # FIXME: Remove this when all of Rack and Rails have learned how to
+ # properly use encodings
+ before_filter :params_filter
+
+ def params_filter
+ if RUBY_VERSION >= '1.9' && defined?(Rails) && Rails::VERSION::MAJOR < 3
+ self.utf8nize!(params)
+ end
+ end
+
+ def utf8nize!(obj)
+ if obj.is_a? String
+ obj.respond_to?(:force_encoding) ? obj.force_encoding("UTF-8") : obj
+ elsif obj.is_a? Hash
+ obj.each {|k, v| obj[k] = self.utf8nize!(v)}
+ elsif obj.is_a? Array
+ obj.each {|v| self.utf8nize!(v)}
+ else
+ obj
+ end
+ end
+
before_filter :user_setup, :check_if_login_required, :set_localization
filter_parameter_logging :password