From 496d744fa31665de810b404de968ba86ed87c319 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 9 Aug 2016 10:35:59 -0700 Subject: Allow specifying encoding of parameters by action At GitHub we need to handle parameter encodings that are not UTF-8. This patch allows us to specify encodings per parameter per action. --- .../action_controller/metal/parameter_encoding.rb | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 actionpack/lib/action_controller/metal/parameter_encoding.rb (limited to 'actionpack/lib/action_controller/metal/parameter_encoding.rb') diff --git a/actionpack/lib/action_controller/metal/parameter_encoding.rb b/actionpack/lib/action_controller/metal/parameter_encoding.rb new file mode 100644 index 0000000000..f5d3dabb45 --- /dev/null +++ b/actionpack/lib/action_controller/metal/parameter_encoding.rb @@ -0,0 +1,29 @@ +module ActionController + module ParameterEncoding + extend ActiveSupport::Concern + + module ClassMethods + def inherited(klass) + super + klass.setup_param_encode + end + + def setup_param_encode + @_parameter_encodings = {} + end + + def encoding_for_param(action, param) + if @_parameter_encodings[action.to_s] && @_parameter_encodings[action.to_s][param.to_s] + @_parameter_encodings[action.to_s][param.to_s] + else + ::Encoding::UTF_8 + end + end + + def parameter_encoding(action, param_name, encoding) + @_parameter_encodings[action.to_s] ||= {} + @_parameter_encodings[action.to_s][param_name.to_s] = encoding + end + end + end +end -- cgit v1.2.3