Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Routing: double escape url segments

#2574

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.

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

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. edbond
    edbond
    • Assigned user changed from Yehuda Katz (wycats) to josh

    May 19th, 2009 @ 01:12 PM

  2. josh
    josh
    • State changed from new to open
    • Milestone cleared.

    May 25th, 2009 @ 05:29 PM

  3. Repository
  4. Dan Byström
    Dan Byström

    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.

    October 6th, 2009 @ 04:59 PM

  5. Dan Byström
    Dan Byström

    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
    

    February 11th, 2010 @ 06:55 AM