Ruby 1.9: don't assume params are US-ASCII. Hands off the encoding.

This commit is contained in:
Jeremy Kemper
2009-11-04 16:11:59 -08:00
parent dc1816da30
commit a8ed10546d
2 changed files with 7 additions and 1 deletions

View File

@@ -20,7 +20,12 @@ module ActionDispatch
params = env[PARAMETERS_KEY]
merge_default_action!(params)
split_glob_param!(params) if @glob_param
params.each { |key, value| params[key] = URI.unescape(value) if value.is_a?(String) }
params.each do |key, value|
if value.is_a?(String)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
params[key] = URI.unescape(value)
end
end
if env['action_controller.recognize']
[200, {}, params]

View File

@@ -450,6 +450,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
assert_equal({:controller => "content", :action => 'show_page', :id => 'foo'}, rs.recognize_path("/page/foo"))
token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in russian
token.force_encoding(Encoding::BINARY) if token.respond_to?(:force_encoding)
escaped_token = CGI::escape(token)
assert_equal '/page/' + escaped_token, rs.generate(:controller => 'content', :action => 'show_page', :id => token)