Skip to content

Commit 2badf46

Browse files
author
Petr Pchelko
committed
Fix #81543: parse_url omits leading slash in windows paths
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. For all intents and purposes 'file:///c:/' and 'file://localhost/c:/' URLs are equivalent, so parsing them differently is a surprising behaviour. Other popular languages like Java or JavaScript preserve the leading slash character as well. This effectively reverts commit [3]. [1] https://datatracker.ietf.org/doc/html/rfc8089#section-2 [2] https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 [3] 4505a61
1 parent 9962aa9 commit 2badf46

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

ext/standard/tests/url/parse_url_basic_001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ echo "Done";
806806
["scheme"]=>
807807
string(4) "file"
808808
["path"]=>
809-
string(3) "a:/"
809+
string(4) "/a:/"
810810
}
811811

812812
--> file:///ab:/: array(2) {
@@ -820,14 +820,14 @@ echo "Done";
820820
["scheme"]=>
821821
string(4) "file"
822822
["path"]=>
823-
string(3) "a:/"
823+
string(4) "/a:/"
824824
}
825825

826826
--> file:///@:/: array(2) {
827827
["scheme"]=>
828828
string(4) "file"
829829
["path"]=>
830-
string(3) "@:/"
830+
string(4) "/@:/"
831831
}
832832

833833
--> file:///:80/: array(2) {

ext/standard/tests/url/parse_url_basic_007.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ echo "Done";
9595
--> http://?:/ : bool(false)
9696
--> http://@?:/ : bool(false)
9797
--> file:///: : string(2) "/:"
98-
--> file:///a:/ : string(3) "a:/"
98+
--> file:///a:/ : string(4) "/a:/"
9999
--> file:///ab:/ : string(5) "/ab:/"
100-
--> file:///a:/ : string(3) "a:/"
101-
--> file:///@:/ : string(3) "@:/"
100+
--> file:///a:/ : string(4) "/a:/"
101+
--> file:///@:/ : string(4) "/@:/"
102102
--> file:///:80/ : string(5) "/:80/"
103103
--> [] : string(2) "[]"
104104
--> http://[x:80]/ : string(1) "/"

ext/standard/tests/url/parse_url_unterminated.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ echo "Done";
812812
["scheme"]=>
813813
string(4) "file"
814814
["path"]=>
815-
string(3) "a:/"
815+
string(4) "/a:/"
816816
}
817817

818818
--> file:///ab:/: array(2) {
@@ -826,14 +826,14 @@ echo "Done";
826826
["scheme"]=>
827827
string(4) "file"
828828
["path"]=>
829-
string(3) "a:/"
829+
string(4) "/a:/"
830830
}
831831

832832
--> file:///@:/: array(2) {
833833
["scheme"]=>
834834
string(4) "file"
835835
["path"]=>
836-
string(3) "@:/"
836+
string(4) "/@:/"
837837
}
838838

839839
--> file:///:80/: array(2) {

ext/standard/url.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
167167
s = e + 3;
168168
if (zend_string_equals_literal_ci(ret->scheme, "file")) {
169169
if (e + 3 < ue && *(e + 3) == '/') {
170-
/* support windows drive letters as in:
171-
file:///c:/somedir/file.txt
172-
*/
173-
if (e + 5 < ue && *(e + 5) == ':') {
174-
s = e + 4;
175-
}
170+
/* support file:/// */
176171
goto just_path;
177172
}
178173
}

0 commit comments

Comments
 (0)