php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81543 parse_url omits leading slash in windows paths
Submitted: 2021-10-19 19:41 UTC Modified: 2021-10-20 08:23 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:0 of 2 (0.0%)
From: ppchelko at wikimedia dot org Assigned:
Status: Open Package: *URL Functions
PHP Version: master-Git-2021-10-19 (Git) OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-10-19 19:41 UTC] ppchelko at wikimedia dot org
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:/"
}

Patches

HcPcEgmp (last revision 2021-10-31 04:13 UTC by sample at email dot tst)
parse_url_windows_paths (last revision 2021-10-19 19:41 UTC by ppchelko at wikimedia dot org)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-19 19:41 UTC] ppchelko at wikimedia dot org
The following patch has been added/updated:

Patch Name: parse_url_windows_paths
Revision:   1634672493
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=parse_url_windows_paths&revision=1634672493
 [2021-10-20 08:23 UTC] cmb@php.net
The commit[1] that would be effectively reverted by your patch,
deliberately removes the leading slash of the path.  While this is
wrong, and URIs like file://localhost/c:/ are treated differently,
I don't think we should fix this for any of the stable branches
(probably not even for PHP 8.1) for BC reasons.

Anyhow, I (generally) recommend to submit pull requests[2] instead
of attaching patches to the bug tracker for better visibility and
discussability.

[1] <https://github.com/php/php-src/commit/4505a611ba8cdcc08505a5ffa0e35bda385bd374>
[2] <https://github.com/php/php-src/pulls>
 [2021-10-20 14:37 UTC] ppchelko at wikimedia dot org
The following pull request has been associated:

Patch Name: Fix #81543: parse_url omits leading slash in windows paths
On GitHub:  https://github.com/php/php-src/pull/7598
Patch:      https://github.com/php/php-src/pull/7598.patch
 [2021-10-31 04:12 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653567
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653567
 [2021-10-31 04:12 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653571
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653571
 [2021-10-31 04:12 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653573
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653573
 [2021-10-31 04:12 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653576
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653576
 [2021-10-31 04:12 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653578
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653578
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653580
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653580
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653583
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653583
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653585
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653585
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653587
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653587
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653589
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653589
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653592
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653592
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653595
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653595
 [2021-10-31 04:13 UTC] sample at email dot tst
The following patch has been added/updated:

Patch Name: HcPcEgmp
Revision:   1635653596
URL:        https://bugs.php.net/patch-display.php?bug=81543&patch=HcPcEgmp&revision=1635653596
 [2023-01-04 11:38 UTC] marlynrasavong at gmail dot com
I have the exact same problem. Have tried a variety of things	
me too facing the similar issues.
(https://www.checkmyrota.net/)github.com
 [2023-02-22 19:16 UTC] dtriton3345 at gmail dot com
(https://images.google.co.zm/url?q=https://is.gd/flviBL).github.com
(https://images.google.co.zw/url?q=https://is.gd/onjunA).github.com
(https://images.google.tt/url?q=https://is.gd/k5CXSY).github.com
(https://www.googleadservices.com/url?q=https%3A%2F%2Fis.gd/k5CXSY%2F).github.com
(https://rssfeeds.usatoday.com/~/t/0/0/mmajunkie/~https://seo11.pro).github.com
(https://www.googleadservices.com/url?q=https%3A%2F%2Fseo11.pro%2F).github.com
(https://www.ebay-kleinanzeigen.de/externer-link-weiterleitung.html?to=http%3A%2F%2Fis.gd/k5CXSY%2F).github.com
(https://images.google.co.uk/url?q=https://is.gd/ayC6pq).github.com
(https://images.google.com/url?q=https://kibla.de).github.com
(https://images.google.com.uy/url?q=https://is.gd/zN3yKw).github.com
(https://images.google.co.uz/url?q=https://is.gd/A047Hu).github.com
(https://images.google.com.vc/url?q=https://is.gd/NCP2kb).github.com
(https://images.google.co.ve/url?q=http://chilp.it/d899a74).github.com
(https://images.google.vg/url?q=http://chilp.it/4635bad).github.com
(https://images.google.co.vi/url?q=http://chilp.it/dfc6883).github.com
(https://images.google.com.vn/url?q=https://is.gd/SQkWhj).github.com
(https://images.google.vu/url?q=https://is.gd/XktFvi).github.com
(https://images.google.ws/url?q=http://chilp.it/6f1c7c6).github.com
(https://images.google.co.za/url?q=http://chilp.it/7af3712).github.com
(https://images.google.co.zm/url?q=http://chilp.it/d0a7b42).github.com
(https://images.google.co.zw/url?q=https://is.gd/IlrEDs).github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC