Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect causes InvalidURIError when spaces are used in the url #3118

Closed
jasonkim opened this issue Sep 23, 2011 · 5 comments
Closed

Redirect causes InvalidURIError when spaces are used in the url #3118

jasonkim opened this issue Sep 23, 2011 · 5 comments

Comments

@jasonkim
Copy link

Redirect uses params to reconstruct the url and params are not url encoded. This causes URI.parse to fail during redirection.

See actionpack/lib/action_dispatch/routing/redirection.rb line 91

@moiristo
Copy link

I have the same problem when an invalid URL is requested:

-------------------------------
Request:
-------------------------------

 * URL       : http://example.com/assets/+%20option.html%20+
 * IP address: 62.163.243.105
 * Parameters: {"path"=>"assets/+ option", "format"=>"html +"}
 * Rails root: /home/deploy/production/releases/20110928165944

-------------------------------
Backtrace:
-------------------------------

 /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:156:in `split'
 /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:174:in `parse'
 /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/uri/common.rb:628:in `parse'
 actionpack (3.1.0) lib/action_dispatch/routing/redirection.rb:91:in `block in redirection_proc'
 rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `call'
 rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
 rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
 rack-mount (0.8.3) lib/rack/mount/code_generation.rb:82:in `optimized_each'
 rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
 rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
 actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call'

It should catch the error and return an appropriate http status instead (406?)

@moiristo
Copy link

For me, it helped to escape the URI that I was passing to Redirect, so instead of redirect{ "http://example.com/assets/+%20option.html%20+"} I use redirect{ URI.escape("http://example.com/assets/+%20option.html%20+") }

@richhollis
Copy link

I've also found that URI.escape solved my problem for the following sample url. Before using URI.escape I too was getting InvalidURIError.

http://www.comet.co.uk/p/Coffee-Makers/buy-GAGGIA-CLASSIC-RI816140-Coffee-Maker/412414?_$ja=kw:{keyword}%7Ccgn:pla%26%7Ctsid:21543%7Ccn:plaKitchen+%26+Home%7Cmt:{MatchType}%7Ccrid:11597898546&gclid=CODVi-mS4q4CFYImtAodfHFiXQ

@steveklabnik
Copy link
Member

It looks to me like this may be fixed now, is this still a problem?

@pixeltrix
Copy link
Contributor

@steveklabnik yes, that will have fixed it - closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants