##// END OF EJS Templates
Ruby1.9: enforce UTF-8 encodings on the params hash on Rails2 (#4050, #4796)...
Toshi MARUYAMA -
r8594:24d73d464465
parent child
Show More
@@ -43,6 +43,28 class ApplicationController < ActionController::Base
43 end
43 end
44 end
44 end
45
45
46 # FIXME: Remove this when all of Rack and Rails have learned how to
47 # properly use encodings
48 before_filter :params_filter
49
50 def params_filter
51 if RUBY_VERSION >= '1.9' && defined?(Rails) && Rails::VERSION::MAJOR < 3
52 self.utf8nize!(params)
53 end
54 end
55
56 def utf8nize!(obj)
57 if obj.is_a? String
58 obj.respond_to?(:force_encoding) ? obj.force_encoding("UTF-8") : obj
59 elsif obj.is_a? Hash
60 obj.each {|k, v| obj[k] = self.utf8nize!(v)}
61 elsif obj.is_a? Array
62 obj.each {|v| self.utf8nize!(v)}
63 else
64 obj
65 end
66 end
67
46 before_filter :user_setup, :check_if_login_required, :set_localization
68 before_filter :user_setup, :check_if_login_required, :set_localization
47 filter_parameter_logging :password
69 filter_parameter_logging :password
48
70
General Comments 0
You need to be logged in to leave comments. Login now