Skip to content

Instantly share code, notes, and snippets.

@yury
Created March 2, 2010 14:27
Show Gist options
  • Save yury/319538 to your computer and use it in GitHub Desktop.
Save yury/319538 to your computer and use it in GitHub Desktop.
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
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