0

What's the difference between URI.escape and CGI.escape? this post was talking about replacing URI.escape with CGI::escape as URI.escape has been obsolete. In our rails 3.2 app, URI.escape was used for redirect_to. Here is two cases in our rails app:

URI.escape(SUBURI + '/user_menus')
URI.escape(SUBURI + '/authentify/signin')

Here are the match in routes.rb:

match '/signin',  :to => 'authentify::sessions#new'
match '/user_menus', :to => 'user_menus#index'
match '/view_handler', :to => 'authentify::application#view_handler'

After replacing with CGI::escape, there is error:

 ERROR URI::InvalidURIError: the scheme http does not accept registry part:

After removing the CGI::escape, the error disappears. Another example:

redirect_to CGI::escape(SUBURI + "/authentify/view_handler?index=0&msg=Insufficient Access Right! for action=#{action} and resource=#{resource}")

After replacing with CGI::escape, there is the error (as above).

What's wrong with the use of CGI::escape above? What's the exact equivalent of URI.escape? ? Also when will URI.escape be completely phased out?

Community
  • 1
  • 1
user938363
  • 9,990
  • 38
  • 137
  • 303
  • irb(main):001:0> URI.escape('/nbhy/projectx_projects_path') => "/nbhy/projectx_projects_path" irb(main):002:0> CGI::escape('/nbhy/projectx_projects_path') => "%2Fnbhy%2Fprojectx_projects_path" – user938363 Nov 04 '13 at 17:57
  • URL helper is something new to us but I do see reason of why not if URL helper is a viable solution. Currently we are using URL.escape for almost every redirect_to in the app. We notice that it was deprecated and is looking for its equivalent. We are looking for something similar to URI.escape to handle the URL escaping. – user938363 Nov 04 '13 at 19:03
  • ruby-doc.org/stdlib-2.0.0/libdoc/uri/rdoc/URI/Escape.html. There is URI.escape module in ruby 2.0.0. Why was it deprecated? – user938363 Nov 04 '13 at 19:36
  • /authentify/view_handler is a method to record the previous page visited. – user938363 Nov 04 '13 at 19:36
  • We are using helper if you meant _path generated by routes. – user938363 Nov 04 '13 at 20:41

0 Answers0