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

From: Date: Wed, 20 Oct 2021 08:23:56 +0000
Subject: Bug #81543 [Opn]: parse_url omits leading slash in windows paths
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237294@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81543&edit=1 ID: 81543 Updated by: cmb@php.net Reported by: ppchelko at wikimedia dot org Summary: parse_url omits leading slash in windows paths Status: Open Type: Bug Package: *URL Functions Operating System: Any PHP Version: master-Git-2021-10-19 (Git) Block user comment: N Private report: N New Comment: 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> Previous Comments: ------------------------------------------------------------------------ [2021-10-19 19:41:34] 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-19 19:41:09] 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:/" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81543&edit=1

« previous php.bugs (#237294) next »