#1224: Support for protocol relative URL generation
-------------------------+--------------------------------------------------
 Reporter:  graste       |       Owner:  dominik                                
            
     Type:  enhancement  |      Status:  new                                    
            
 Priority:  normal       |   Milestone:  1.0.3                                  
            
Component:  routing      |     Version:  1.0.2                                  
            
 Severity:  normal       |    Keywords:  routing route scheme generate protocol 
relative url
Has_patch:  0            |  
-------------------------+--------------------------------------------------
 Hi,

 it seems, that Agavi can't correctly generate protocol relative URLs (that
 is, URLs without specified scheme component).

 If we take the usual pattern of:
 {{{
 
scheme://[authority[:passwo...@](host_name|host_address)[:port][/hierarchical/path/to/resource[?search_string][#fragment_id]]
 }}}

 setting Agavi's routing options of 'scheme' to '''false''' or '''null'''
 or an '''empty string''' doesn't always generate correct URLs as Agavi
 always uses '://'. This is not okay for protocol relative URLs that e.g.
 may be used to mitigate the Internet Explorer "mixed content" warning on
 pages with mixed HTTP and HTTPS content.

 Examples for protocol relative URLs:

 {{{

 <script src="//some.domain.tld/js/script.js" type="text/javascript" />

 <link type="text/css" rel="stylesheet" href="//domain.tld/style.css" />

 <img src="//domain.tld/img.jpg" />

 }}}


 A quick reseach gave me [http://www.apps.ietf.org/rfc/rfc3986.html#sec-5.3
 RFC3986] which states, that the ':' is only added if a scheme is defined
 (when I'm interpreting this correctly and this RFC is relevant).


 '''Given:'''

 1) $ro->gen('some.route', array(), array('scheme' => false));

 2) $ro->gen('some.route', array(), array('scheme' => ""));

 3) $ro->gen('some.route', array(), array('relative' => false, 'scheme' =>
 ' '));


 '''Expected:'''

 //some.domain.tld/some/route

 //some.domain.tld/some/route

 //some.domain.tld/some/route

 '''Actual result:'''

 some.domain.tld/some/route

 ://some.domain.tld/some/route

 ://some.domain.tld/some/route


 '''Browsers (basehref set to http://some.domain.tld:/) then link like
 this:'''

 http://some.domain.tld/some.domain.tld/some/route

 http://some.domain.tld/://some.domain.tld/some/route

 http://some.domain.tld/://some.domain.tld/some/route

 whileas with the following quick test hack the URLs will be correctly
 generated as:

 http://some.domain.tld/some/route

 https://some.domain.tld/some/route


 If '''scheme => false''' should be left like it was (backwards
 compatibility?), a quick hack to support protocol relative URLs would be
 via '''empty scheme strings''' like this:

 {{{
 Index: AgaviWebRouting.class.php
 ===================================================================
 --- AgaviWebRouting.class.php   (Revision 4420)
 +++ AgaviWebRouting.class.php   (Arbeitskopie)
 @@ -392,7 +392,14 @@
                                 $authority = $options['authority'];
                         }

 -                       $retval = ($scheme === null ? '' : $scheme .
 '://') . $authority . $retval;
 +            if (null === $scheme) {
 +                $scheme = '';
 +            elseif ('' === trim($scheme)) {
 +                $scheme = '//';
 +            } else {
 +                $scheme = '://';
 +            }
 +            $retval = $scheme . $authority . $retval;
                 }

                 if($options['fragment'] !== null) {
 @@ -419,4 +426,4 @@

  }

 -?>
 \ No newline at end of file
 +?>
 }}}

-- 
Ticket URL: <http://trac.agavi.org/ticket/1224>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5



_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets

Reply via email to