Skip to content

Commit f5a0c5a

Browse files
committed
ticket-78385 an empty string in parse_url() return when question mark is the last
1 parent f6dea34 commit f5a0c5a

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #78385 parse_url() does not include 'query' when question mark is the last char
3+
--FILE--
4+
<?php
5+
6+
var_dump(parse_url('http://example.com/foo?'));
7+
var_dump(parse_url('http://example.com/foo?', PHP_URL_QUERY));
8+
9+
?>
10+
--EXPECT--
11+
array(4) {
12+
["scheme"]=>
13+
string(4) "http"
14+
["host"]=>
15+
string(11) "example.com"
16+
["path"]=>
17+
string(4) "/foo"
18+
["query"]=>
19+
string(0) ""
20+
}
21+
string(0) ""

ext/standard/tests/url/parse_url_basic_001.phpt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,36 @@ echo "Done";
144144
string(10) "/index.php"
145145
}
146146

147-
--> www.php.net/?: array(1) {
147+
--> www.php.net/?: array(2) {
148148
["path"]=>
149149
string(12) "www.php.net/"
150+
["query"]=>
151+
string(0) ""
150152
}
151153

152-
--> www.php.net:80/?: array(3) {
154+
--> www.php.net:80/?: array(4) {
153155
["host"]=>
154156
string(11) "www.php.net"
155157
["port"]=>
156158
int(80)
157159
["path"]=>
158160
string(1) "/"
161+
["query"]=>
162+
string(0) ""
159163
}
160164

161-
--> http://www.php.net/?: array(3) {
165+
--> http://www.php.net/?: array(4) {
162166
["scheme"]=>
163167
string(4) "http"
164168
["host"]=>
165169
string(11) "www.php.net"
166170
["path"]=>
167171
string(1) "/"
172+
["query"]=>
173+
string(0) ""
168174
}
169175

170-
--> http://www.php.net:80/?: array(4) {
176+
--> http://www.php.net:80/?: array(5) {
171177
["scheme"]=>
172178
string(4) "http"
173179
["host"]=>
@@ -176,6 +182,8 @@ echo "Done";
176182
int(80)
177183
["path"]=>
178184
string(1) "/"
185+
["query"]=>
186+
string(0) ""
179187
}
180188

181189
--> http://www.php.net:80/index.php: array(4) {
@@ -290,7 +298,7 @@ echo "Done";
290298
string(10) "/index.php"
291299
}
292300

293-
--> http://www.php.net:80/index.php?: array(4) {
301+
--> http://www.php.net:80/index.php?: array(5) {
294302
["scheme"]=>
295303
string(4) "http"
296304
["host"]=>
@@ -299,6 +307,8 @@ echo "Done";
299307
int(80)
300308
["path"]=>
301309
string(10) "/index.php"
310+
["query"]=>
311+
string(0) ""
302312
}
303313

304314
--> http://www.php.net:80/#foo: array(5) {
@@ -314,7 +324,7 @@ echo "Done";
314324
string(3) "foo"
315325
}
316326

317-
--> http://www.php.net:80/?#: array(4) {
327+
--> http://www.php.net:80/?#: array(5) {
318328
["scheme"]=>
319329
string(4) "http"
320330
["host"]=>
@@ -323,6 +333,8 @@ echo "Done";
323333
int(80)
324334
["path"]=>
325335
string(1) "/"
336+
["query"]=>
337+
string(0) ""
326338
}
327339

328340
--> http://www.php.net:80/?test=1: array(5) {
@@ -731,11 +743,13 @@ echo "Done";
731743
string(4) "/:80"
732744
}
733745

734-
--> http://x:?: array(2) {
746+
--> http://x:?: array(3) {
735747
["scheme"]=>
736748
string(4) "http"
737749
["host"]=>
738750
string(1) "x"
751+
["query"]=>
752+
string(0) ""
739753
}
740754

741755
--> x:blah.com: array(2) {
@@ -754,11 +768,13 @@ echo "Done";
754768

755769
--> x://::abc/?: bool(false)
756770

757-
--> http://::?: array(2) {
771+
--> http://::?: array(3) {
758772
["scheme"]=>
759773
string(4) "http"
760774
["host"]=>
761775
string(1) ":"
776+
["query"]=>
777+
string(0) ""
762778
}
763779

764780
--> http://::#: array(2) {

ext/standard/tests/url/parse_url_basic_008.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ echo "Done";
3838
--> http://www.php.net:80 : NULL
3939
--> http://www.php.net:80/ : NULL
4040
--> http://www.php.net/index.php : NULL
41-
--> www.php.net/? : NULL
42-
--> www.php.net:80/? : NULL
43-
--> http://www.php.net/? : NULL
44-
--> http://www.php.net:80/? : NULL
41+
--> www.php.net/? : string(0) ""
42+
--> www.php.net:80/? : string(0) ""
43+
--> http://www.php.net/? : string(0) ""
44+
--> http://www.php.net:80/? : string(0) ""
4545
--> http://www.php.net:80/index.php : NULL
4646
--> http://www.php.net:80/foo/bar/index.php : NULL
4747
--> http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php : NULL
@@ -52,9 +52,9 @@ echo "Done";
5252
--> http://www.php.net:80/this/../a/../deep/directory/ : NULL
5353
--> http://www.php.net:80/this/is/a/very/deep/directory/../file.php : NULL
5454
--> http://www.php.net:80/index.php : NULL
55-
--> http://www.php.net:80/index.php? : NULL
55+
--> http://www.php.net:80/index.php? : string(0) ""
5656
--> http://www.php.net:80/#foo : NULL
57-
--> http://www.php.net:80/?# : NULL
57+
--> http://www.php.net:80/?# : string(0) ""
5858
--> http://www.php.net:80/?test=1 : string(6) "test=1"
5959
--> http://www.php.net/?test=1& : string(7) "test=1&"
6060
--> http://www.php.net:80/?& : string(1) "&"
@@ -91,11 +91,11 @@ echo "Done";
9191
--> gg:9130731 : NULL
9292
--> http://user:@pass@host/path?argument?value#etc : string(14) "argument?value"
9393
--> http://10.10.10.10/:80 : NULL
94-
--> http://x:? : NULL
94+
--> http://x:? : string(0) ""
9595
--> x:blah.com : NULL
9696
--> x:/blah.com : NULL
9797
--> x://::abc/? : bool(false)
98-
--> http://::? : NULL
98+
--> http://::? : string(0) ""
9999
--> http://::# : NULL
100100
--> x://::6.5 : NULL
101101
--> http://?:/ : bool(false)

ext/standard/url.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
307307
if (p < e) {
308308
ret->query = zend_string_init(p, (e - p), 0);
309309
php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query));
310+
} else {
311+
ret->query = ZSTR_EMPTY_ALLOC();
310312
}
311313
e = p-1;
312314
}

0 commit comments

Comments
 (0)