Skip to content

Commit e65bdff

Browse files
committed
tests + BFN
1 parent 8e0cf44 commit e65bdff

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PHP NEWS
7777
number of backslashes). (David Soria Parra, Pierre)
7878
- Fixed bug #39534 (Error in maths to calculate of
7979
ZEND_MM_ALIGNED_MIN_HEADER_SIZE). (wharmby at uk dot ibm dot com, Dmitry)
80+
- Fixed bug #39458 (ftp_nlist() returns false on empty dirs). (Nuno)
8081
- Fixed bug #39454 (Returning a SOAP array segfaults PHP). (Dmitry)
8182
- Fixed bug #39445 (Calling debug_backtrace() in the __toString() function
8283
produces a crash). (Dmitry)

ext/ftp/tests/bug39458-2.phpt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #39458: ftp_nlist() returns false on empty directories (other server behaviour)
3+
--SKIPIF--
4+
<?php
5+
require 'skipif.inc';
6+
?>
7+
--FILE--
8+
<?php
9+
$bug39458=1;
10+
require 'server.inc';
11+
12+
$ftp = ftp_connect('127.0.0.1', $port);
13+
if (!$ftp) die("Couldn't connect to the server");
14+
15+
var_dump(ftp_login($ftp, 'user', 'pass'));
16+
17+
var_dump(ftp_nlist($ftp, ''));
18+
var_dump(ftp_nlist($ftp, 'emptydir'));
19+
var_dump(ftp_nlist($ftp, 'bogusdir'));
20+
21+
ftp_close($ftp);
22+
?>
23+
--EXPECT--
24+
bool(true)
25+
array(3) {
26+
[0]=>
27+
string(5) "file1"
28+
[1]=>
29+
string(5) "file1"
30+
[2]=>
31+
string(9) "file
32+
b0rk"
33+
}
34+
array(0) {
35+
}
36+
bool(false)

ext/ftp/tests/bug39458.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #39458: ftp_nlist() returns false on empty directories
3+
--SKIPIF--
4+
<?php
5+
require 'skipif.inc';
6+
?>
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$ftp = ftp_connect('127.0.0.1', $port);
12+
if (!$ftp) die("Couldn't connect to the server");
13+
14+
var_dump(ftp_login($ftp, 'user', 'pass'));
15+
16+
var_dump(ftp_nlist($ftp, ''));
17+
var_dump(ftp_nlist($ftp, 'emptydir'));
18+
var_dump(ftp_nlist($ftp, 'bogusdir'));
19+
20+
ftp_close($ftp);
21+
?>
22+
--EXPECT--
23+
bool(true)
24+
array(3) {
25+
[0]=>
26+
string(5) "file1"
27+
[1]=>
28+
string(5) "file1"
29+
[2]=>
30+
string(9) "file
31+
b0rk"
32+
}
33+
array(0) {
34+
}
35+
bool(false)

ext/ftp/tests/server.inc

+27
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,33 @@ while($buf = fread($s, 4098)) {
201201
change_dir($m[1]);
202202
fputs($s, "250 CWD command successful.\r\n");
203203

204+
} elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) {
205+
206+
if (isset($m[1]) && $m[1] === 'bogusdir') {
207+
fputs($s, "250 $m[1]: No such file or directory\r\n");
208+
continue;
209+
}
210+
211+
// there are some servers that don't open the ftp-data socket if there's nothing to send
212+
if (isset($bug39458) && isset($m[1]) && $m[1] === 'emptydir') {
213+
fputs($s, "226 Transfer complete.\r\n");
214+
continue;
215+
}
216+
217+
fputs($s, "150 File status okay; about to open data connection\r\n");
218+
219+
if (!$fs = stream_socket_client("tcp://$host:$port")) {
220+
fputs($s, "425 Can't open data connection\r\n");
221+
continue;
222+
}
223+
224+
if (empty($m[1]) || $m[1] !== 'emptydir') {
225+
fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n");
226+
}
227+
228+
fputs($s, "226 Closing data Connection.\r\n");
229+
fclose($fs);
230+
204231
} elseif (preg_match("~^MKD ([A-Za-z./]+)\r\n$~", $buf, $m)) {
205232
if (isset($bug7216)) {
206233
fputs($s, "257 OK.\r\n");

0 commit comments

Comments
 (0)