rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* Trouble with Unicode in URLs
@ 2010-01-15 16:26 Gaius
  2010-01-15 16:43 ` Iñaki Baz Castillo
  0 siblings, 1 reply; 11+ messages in thread
From: Gaius @ 2010-01-15 16:26 UTC (permalink / raw)
  To: Rack Development

I have a Rails app in which I'd like to use some Unicode URLs:

    # in routes.rb:
    map.resources 'proteges', :as => 'protégés', :only => [:index]

When I go to http://localhost:3000/protégés, I get

    No route matches "/prot%C3%A9g%C3%A9s" with {:method=>:get}

That was on Mongrel, though I also tried Passenger.  The fix was to
rewrite the REQUEST_URI environment variable in a Rack middleware:

    require 'cgi'

    class FixUnicodeUrlsMiddleware

      ENVIRONMENT_VARIABLES_TO_FIX = [
        'PATH_INFO', 'REQUEST_PATH', 'REQUEST_URI'
      ]

      def initialize(app)
        @app = app
      end

      def call(env)
        ENVIRONMENT_VARIABLES_TO_FIX.each do |var|
          env[var] = CGI.unescape(env[var]) if env[var] =~ /%[A-Za-
z0-9]/
        end
        @app.call(env)
      end

    end

I'm sure that implementation could cause some problems, though.

See also my question on Stackoverflow:
http://stackoverflow.com/questions/2051553/how-do-i-use-utf-in-a-rails-url

Does anyone have any thoughts on how to add Unicode support to Rack?

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-01-15 21:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-15 16:26 Trouble with Unicode in URLs Gaius
2010-01-15 16:43 ` Iñaki Baz Castillo
2010-01-15 16:46   ` Gaius
2010-01-15 17:03     ` Iñaki Baz Castillo
2010-01-15 17:13       ` Gaius
2010-01-15 17:16         ` Gaius
2010-01-15 17:48           ` Iñaki Baz Castillo
2010-01-15 17:21         ` Gaius
2010-01-15 17:49           ` Iñaki Baz Castillo
2010-01-15 19:23             ` Gaius
2010-01-15 21:08               ` Iñaki Baz Castillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).