This project is archived and is in readonly mode.

#2574 ✓resolved
edbond

Routing: double escape url segments

Reported by edbond | April 28th, 2009 @ 11:35 AM

URL can have encoded utf-8 chars like:


http://ru.wikipedia.org/wiki/%D0%91%D0%BE%D1%82%D1%82%D0%B8%D1%87%D0%B5%D0%BB%D0%BB%D0%B8

To match such routes I use (routes.rb):


map.city URI.escape("/Карта--:title--:id"), ...

rails double encodes static segments and url_for generate incorrect links: % escaped to %2D and we get


%25D0%259A%25D0%25B0%25D1%2580%25D1%2582%25D0%25B0

instead of


%D0%9A%D0%B0%D1%80%D1%82%D0%B0

This patch adds '%' to RESERVED_PCHAR so urls doesn't encoded double. Test included.

Comments and changes to this ticket

  • edbond

    edbond May 19th, 2009 @ 01:12 PM

    • Assigned user changed from “Yehuda Katz (wycats)” to “josh”
  • josh

    josh May 25th, 2009 @ 05:29 PM

    • State changed from “new” to “open”
    • Milestone cleared.
  • Repository

    Repository May 27th, 2009 @ 09:02 PM

    • State changed from “open” to “resolved”
  • Dan Byström

    Dan Byström October 6th, 2009 @ 04:59 PM

    I suspecting that the routing string (/Карта--:title--:id) shouldn't be escaped. It makes sense to think that the rails developers escapes the route stings for us.

    map.city URI.escape("/Карта--:title--:id"), ... it should be
    map.city "/Карта--:title--:id", ... The unescaped code works just fine when I host/run my application with Apache+Phusion Passenger. However, in my development environment (Aptana Studio or the script/server command) then I have to escape all my routes and apply your routing_uri_escape.patch.

    Since I'm a newbe I have no clue what causes this escape bug. Still, I'm quite sure that the escape bug needs a second check.

  • Dan Byström

    Dan Byström February 11th, 2010 @ 06:55 AM

    I think this is how you want to solve this problem.

    # config/routes.rb
    
    map.city "/Карта--:title--:id", :controller => 'foo', :action => 'bar'
    
    # config/initializers/new_rails_defaults.rb
    
    module ActionController
      module Routing
        class RouteSet
          def recognize(request)
            params = recognize_path(URI.unescape(request.path), extract_request_environment(request))
            request.path_parameters = params.with_indifferent_access
            "#{params[:controller].to_s.camelize}Controller".constantize
          end
        end
      end
    end
    

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages