From: Gaius <james.a.rosen@gmail.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Trouble with Unicode in URLs
Date: Fri, 15 Jan 2010 08:26:28 -0800 (PST) [thread overview]
Message-ID: <aeb13781-3d7b-4d71-99a0-6392320827c9@e27g2000yqd.googlegroups.com> (raw)
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?
next reply other threads:[~2010-01-15 16:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-15 16:26 Gaius [this message]
2010-01-15 16:43 ` Trouble with Unicode in URLs 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://groups.google.com/group/rack-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aeb13781-3d7b-4d71-99a0-6392320827c9@e27g2000yqd.googlegroups.com \
--to=rack-devel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).