This project is archived and is in readonly mode.
redirect_to a custom protocol is causing errors
Reported by Noah Hendrix | June 30th, 2010 @ 02:44 AM
If you redirect_to a custom protocol, like for to launch an iPhone app, and the URL part starts with a number, it throw an error. If I put a letter after the protocol (e.g. "surveysays://a" + params[:id]) the error goes away and it redirects as expected.
#if they are using an iphone and visiting this page we should redirect them to the app to take the survey
if mobile_device? && !@survey.nil?
redirect_to("surveysays://" + params[:id])
else
redirect_to survey_path(@survey.access_key)
end
2010-06-29 20:42:13] ERROR URI::InvalidURIError: the scheme surveysays does not accept registry part: 68419 (or bad hostname?)
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/uri/generic.rb:746:in `rescue in merge'
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/uri/generic.rb:743:in `merge'
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in `setup_header'
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in `send_response'
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/webrick/httpserver.rb:86:in `run'
/Users/noahhendrix/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Comments and changes to this ticket
-
Noah Hendrix June 30th, 2010 @ 02:45 AM
This is Rails 3.0.0.beta4 on ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.4.0]
-
José Valim June 30th, 2010 @ 12:12 PM
- Assigned user set to José Valim
- Importance changed from to Low
Could you please provide a patch with a failing test case in Rails suite? Thanks a lot!
-
Bruno Michel June 30th, 2010 @ 01:26 PM
If you redirect_to a custom protocol, like for to launch an iPhone app, and the URL part starts with a number, it throw an error. If I put a letter after the protocol (e.g. "surveysays://a" + params[:id]) the error goes away and it redirects as expected.
I think it's the expected behaviour: AFAIK, the first URL doesn't respect the RFC 2396, but the second does.
-
Noah Hendrix June 30th, 2010 @ 04:27 PM
From my reading of the RFC it seems that what I wanted to is perfectly allowed. Below I followed the path through to show what options my particular example should fall through to. I surrounded the relevant choices with asterisks. I've never read these kind of documents before so I am possibly missing something, let me know if that is the case.
URI-reference = [ **absoluteURI** | relativeURI ] [ "#" fragment ] --> absoluteURI = scheme ":" ( **hier_part** | opaque_part ) --> hier_part = ( **net_path** | abs_path ) [ "?" query ] --> net_path = "//" **authority** [ abs_path ] --> authority = **server** | reg_name --> server = [ [ userinfo "@" ] **hostport** ] --> hostport = **host** [ ":" port ] --> host = **hostname** | IPv4address --> hostname = *( **domainlabel** "." ) toplabel [ "." ] --> domainlabel = **alphanum** | alphanum *( alphanum | "-" ) alphanum --> alphanum = alpha | **digit** --> digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
-
Bruno Michel June 30th, 2010 @ 05:05 PM
--> hostname = *( domainlabel "." ) toplabel [ "." ]
The trick is on this line. It should be read as: the toplabel is mandatory, but if you want, you can add a domainlabel plus a dot before the toplevel (in fact, you can repeat this operation of adding a domainlabel plus a dot several times).
So, your number should be a toplevel, but it can't as it does not start with an alpha:
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
-
Noah Hendrix June 30th, 2010 @ 05:17 PM
Okay, that makes a lot of sense. So, does that mean if I bought a domain like 42.com, it is technically invalid?
-
Bruno Michel June 30th, 2010 @ 06:49 PM
42.com is valid: 42 is a domainlabel in that case, and com, the toplevel, starts by an alpha char.
-
José Valim July 8th, 2010 @ 10:21 PM
- State changed from new to invalid
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>