Rails (2.3.5 and it seems the same is with edge) with Ruby 1.9
correctly creates and stores utf-8 based routes. But when it comes
to route recognition, it fails to match the route name:
map.home 'начало', controller: :home, action: :index
then
http://localhost/%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%BE
gives
No route matches "/%D0%BD%D0%B0%D1%87%D0%B0%D0%BB%D0%BE" with {:method=>:get}
The reason is that recognize_path does html unescape only after
routes are mapped, and because of this it fails to map raw utf8
stored name against its %XX%XX equivalent.
In 2.3.5 the next patch fixes the issue:
require 'action_pack'
require 'cgi'
module ActionController::Routing
class RouteSet
alias_method :recognize_path_ugly, :recognize_path
def recognize_path(path, environment)
path = CGI::unescape(path).force_encoding('utf-8').encode(invalid: :replace)
recognize_path_ugly(path, environment)
end
end
end
The problem was introduced with http://dev.rubyonrails.org/changeset/6185
which basically tried to fix another issue. Actually fixing it with
the above patch will break the current behaviour of parameters
unescaping, so it should be carefully considered.
The similar issue was raised which also may interfere with this
problem:
https://rails.lighthouseapp.com/projects/8994/tickets/2574-routing-...