Bug #81543 [NEW]: parse_url omits leading slash in windows paths

From: Date: Tue, 19 Oct 2021 19:41:09 +0000
Subject: Bug #81543 [NEW]: parse_url omits leading slash in windows paths
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237288@lists.php.net to get a copy of this message
From:             ppchelko at wikimedia dot org
Operating system: Any
PHP version:      master-Git-2021-10-19 (Git)
Package:          *URL Functions
Bug Type:         Bug
Bug description:parse_url omits leading slash in windows paths

Description:
------------
parse_url looses the leading '/' character in paths with single-letter
Windows drive letters.

According to the RFC8089 Section 2[1]:

> The generic syntax in [RFC3986] includes "path" and "authority"
  components, for each of which only a subset is used in the definition
  of the file URI scheme.  The relevant subset of "path" is "path-
  absolute"

'path-absolute' in RFC3986 is defined as beginning with a '/'
character.

There's also a requirement in RFC3986 section 3.3 [2], that

> If a URI contains an authority component, then the path component
  must either be empty or begin with a slash ("/") character.

For file:///c:/ URL the authority component is present but empty, which
implies 'localhost'. Thus the 'path' component must begin with the '/'
character.

Other popular languages like Java or JavaScript preserve the leading
slash character as well.

[1] https://datatracker.ietf.org/doc/html/rfc8089#section-2
[2] https://datatracker.ietf.org/doc/html/rfc3986#section-3.3


Test script:
---------------
var_dump( parse_url( 'file:///c:/' ) );

Expected result:
----------------
array(2) {
  ["scheme"]=>
  string(4) "file"
  ["path"]=>
  string(4) "/c:/"
}

Actual result:
--------------
array(2) {
  ["scheme"]=>
  string(4) "file"
  ["path"]=>
  string(3) "c:/"
}

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81543&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81543&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81543&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81543&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81543&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81543&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81543&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81543&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81543&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81543&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81543&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81543&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81543&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81543&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81543&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81543&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81543&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81543&r=mysqlcfg


Thread (19 messages)

« previous php.bugs (#237288) next »