Created
August 17, 2012 17:37
-
-
Save loren/3380888 to your computer and use it in GitHub Desktop.
Fix for ArgumentError: invalid byte sequence in UTF-8
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 'action_dispatch/routing/route_set' | |
# Based on https://gist.github.com/2830082 | |
module ActionDispatch | |
module Routing | |
class RouteSet | |
class Dispatcher | |
def call_with_invalid_char_handling(env) | |
uri = CGI::unescape(env["REQUEST_URI"].force_encoding("UTF-8")) | |
# If anything in the REQUEST_URI has an invalid encoding, then raise since it's likely to trigger errors further on. | |
return [400, {'X-Cascade' => 'pass'}, []] if uri.is_a?(String) and !uri.valid_encoding? | |
call_without_invalid_char_handling(env) | |
end | |
alias_method_chain :call, :invalid_char_handling | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@radixhound That would be weird. I am using 3.2.11 but REQUEST_URI is there. Or you can try "ORIGINAL_FULLPATH" instead?