From:             gmirchev at usa dot net
Operating system: Linux
PHP version:      4.3.3
PHP Bug Type:     URL related
Bug description:  parse_url is not RFC 2396 compliant

Description:
------------
parse_url does not correctly handle these relative URLs:

a.cgi?keywords=6:54+
a.cgi?keywords=6:54

In the reproduce code is correct PHP implementation.


Reproduce code:
---------------
        function url_parse($url)
        {
                $parts = array(
                        'scheme' => '',
                        'host' => '',
                        'port' => '',
                        'user' => '',
                        'pass' => '',
                        'path' => '',
                        'query' => '',
                        'fragment' => ''
                );

                # Regular Expression from RFC 2396 (appendix B)
                
preg_match('"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?"',
$url, $matches);
                
                if (array_key_exists(2, $matches)) $parts['scheme'] = $matches[2];
                if (array_key_exists(4, $matches)) $authority = $matches[4];
                if (array_key_exists(5, $matches)) $parts['path'] = $matches[5];
                if (array_key_exists(7, $matches)) $parts['query'] = $matches[7];
                if (array_key_exists(9, $matches)) $parts['fragment'] = $matches[9];
                
                # Extract username, password, host and port from authority
                preg_match('"(([^:@]*)(:([^:@]*))?@)?([^:]*)(:(.*))?"', $authority,
$matches);

                if (array_key_exists(2, $matches)) $parts['user'] = $matches[2];
                if (array_key_exists(4, $matches)) $parts['pass'] = $matches[4];
                if (array_key_exists(5, $matches)) $parts['host'] = $matches[5];
                if (array_key_exists(7, $matches)) $parts['port'] = $matches[7];
                
                return $parts;
        }



-- 
Edit bug report at http://bugs.php.net/?id=25778&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25778&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25778&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25778&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25778&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25778&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25778&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25778&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25778&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25778&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25778&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25778&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25778&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25778&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25778&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25778&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25778&r=float

Reply via email to