From 21a45b4e52f0fcd80849f3b8ac08e8472eca74bd Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sun, 30 Oct 2011 11:24:11 +0100 Subject: [PATCH] [#676] Enforce UTF-8 encodings on the params hash Contributed by Toshi MARUYAMA --- app/controllers/application_controller.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 424c05e0..c5da0b44 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,6 +43,24 @@ 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 + self.utf8nize!(params) if RUBY_VERSION >= '1.9' + 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