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%25D1%2582%25D0%25B0--%D0%9A%D0%B8%D0%B5%D0%B2--30295?page=4
Rails double escapes url?
Also I tried url_for(.... :escape => false), it doesn''t help.
Thanks in advance,
Eduard
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%25D1%2582%25D0%25B0--%D0%9A%D0%B8%D0%B5%D0%B2--30295?page=4
Rails double escapes url?
Also I tried url_for(.... :escape => false), it doesn''t help.
Thanks in advance,
Eduard
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
On Apr 27, 2:31 pm, Eduard Bondarenko
<edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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%25D1%2582%25D0%25B0--...
>
> Rails double escapes url?
>
> Also I tried url_for(.... :escape => false), it doesn''t help.
>
> Thanks in advance,
> Eduard
Much simpler: ActionController::Routing::Segment::RESERVED_PCHAR='':@&=+$,;%'' Ticket / Patch: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2574-routing-double-escape-url-segments On Apr 28, 12:34 pm, edbond <edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On Apr 27, 2:31 pm, Eduard Bondarenko <edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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%25D1%2582%25D0%25B0--... > > > Rails double escapes url? > > > Also I tried url_for(.... :escape => false), it doesn''t help. > > > Thanks in advance, > > Eduard
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
On Apr 28, 1:36 pm, edbond
<edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Much simpler:
>
ActionController::Routing::Segment::RESERVED_PCHAR='':@&=+$,;%''
>
> Ticket /
Patch:https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2...
>
> On Apr 28, 12:34 pm, edbond
<edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > 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
>
> > On Apr 27, 2:31 pm, Eduard Bondarenko
<edb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > 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%25D1%2582%25D0%25B0--...
>
> > > Rails double escapes url?
>
> > > Also I tried url_for(.... :escape => false), it
doesn''t help.
>
> > > Thanks in advance,
> > > Eduard