Forum: Ruby on Rails routing: Unescape urls

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
671af8c4a2d223c7d2e2ede3a0154975?d=identicon&s=25 Eduard Bondarenko (edbond)
on 2009-04-27 13:31
(Received via mailing list)
Hello All,

How to make rails unescape incoming urls? I want to use russian chars
in routes, like:

map.city URI.escape("/Карта--:title--:id"), :controller =>
"cities", :action => "show" It seems to works (page loads) but all
links on page looks like this:
http://localhost/%25D0%259A%25D0%25B0%25D1%2580%25...

Rails double escapes url?

Also I tried url_for(.... :escape => false), it doesn't help.

Thanks in advance,
Eduard
671af8c4a2d223c7d2e2ede3a0154975?d=identicon&s=25 Eduard Bondarenko (edbond)
on 2009-04-28 11:35
(Received via mailing list)
SOLVED:
double escape fix

#
# skip escaping of already escaped value
#
ActionController::Routing::Segment.class_eval(<<-FIX, __FILE__,
__LINE__+1)
  def interpolation_chunk
    value.include?('%') ? value : URI.escape(value, UNSAFE_PCHAR)
  end
FIX

Best regards to All,
Eduard
671af8c4a2d223c7d2e2ede3a0154975?d=identicon&s=25 Eduard Bondarenko (edbond)
on 2009-04-28 12:37
(Received via mailing list)
Much simpler:
ActionController::Routing::Segment::RESERVED_PCHAR=':@&=+$,;%'

Ticket / Patch:
https://rails.lighthouseapp.com/projects/8994-ruby...
671af8c4a2d223c7d2e2ede3a0154975?d=identicon&s=25 Eduard Bondarenko (edbond)
on 2009-04-28 12:53
(Received via mailing list)
err,

to work properly you need to change other constants too.
Add this at top of your routes.rb:

ActionController::Routing::Segment.class_eval(<<-FIX, __FILE__,
__LINE__+1)
  RESERVED_PCHAR=':@&=+$,;%'
  SAFE_PCHAR = "\#{URI::REGEXP::PATTERN::UNRESERVED}\#
{RESERVED_PCHAR}"
  UNSAFE_PCHAR = Regexp.new("[^\#{SAFE_PCHAR}]", false, 'N').freeze
FIX
This topic is locked and can not be replied to.