Created
March 2, 2010 14:27
-
-
Save yury/319538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Fx | |
class UnicodeEnforcer | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
req = Rack::Request.new(env) | |
force_encoding(req.params) | |
@app.call(env) | |
end | |
def force_encoding(on) | |
case on | |
when String | |
on.dup.force_encoding('utf-8') | |
when Array | |
on.map(&method(:force_encoding)) | |
when Hash | |
on.each_pair do | k, v | | |
on[k] = force_encoding(v) | |
end | |
else | |
on | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fx' | |
ActionController::Dispatcher.middleware.insert_after( | |
ActionController::ParamsParser, | |
Fx::UnicodeEnforcer | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment