aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/parameter_encoding.rb
diff options
context:
space:
mode:
authorKerri Miller <kerrizor@github.com>2016-08-09 10:35:59 -0700
committerKerri Miller <kerrizor@github.com>2016-08-09 15:43:01 -0700
commit496d744fa31665de810b404de968ba86ed87c319 (patch)
tree5845602181062927cd72709facbb7d7eb92f6b42 /actionpack/lib/action_controller/metal/parameter_encoding.rb
parent46f511685c91486295a418547bb08c2aa5e49cfc (diff)
downloadrails-496d744fa31665de810b404de968ba86ed87c319.tar.gz
rails-496d744fa31665de810b404de968ba86ed87c319.tar.bz2
rails-496d744fa31665de810b404de968ba86ed87c319.zip
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.
Diffstat (limited to 'actionpack/lib/action_controller/metal/parameter_encoding.rb')
-rw-r--r--actionpack/lib/action_controller/metal/parameter_encoding.rb29
1 files changed, 29 insertions, 0 deletions
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