Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

redirect_to a custom protocol is causing errors

#5010

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'

Reported by Noah Hendrix · June 30th, 2010 @ 02:44 AM

State: invalid
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Noah Hendrix
    Noah Hendrix

    This is Rails 3.0.0.beta4 on ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.4.0]

    June 30th, 2010 @ 02:45 AM

  2. José Valim
    José Valim
    • 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!

    June 30th, 2010 @ 12:12 PM

  3. Bruno Michel
    Bruno Michel

    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.

    June 30th, 2010 @ 01:26 PM

  4. Noah Hendrix
    Noah Hendrix

    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"
    

    June 30th, 2010 @ 04:27 PM

  5. Bruno Michel
    Bruno Michel

    --> 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
    

    June 30th, 2010 @ 05:05 PM

  6. Noah Hendrix
    Noah Hendrix

    Okay, that makes a lot of sense. So, does that mean if I bought a domain like 42.com, it is technically invalid?

    June 30th, 2010 @ 05:17 PM

  7. Bruno Michel
    Bruno Michel

    42.com is valid: 42 is a domainlabel in that case, and com, the toplevel, starts by an alpha char.

    June 30th, 2010 @ 06:49 PM

  8. José Valim
    José Valim
    • State changed from new to invalid

    July 8th, 2010 @ 10:21 PM