From e65bdffab503c973319c2cb460b782f3f2628752 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Fri, 1 Dec 2006 16:37:39 +0000 Subject: [PATCH] tests + BFN --- NEWS | 1 + ext/ftp/tests/bug39458-2.phpt | 36 +++++++++++++++++++++++++++++++++++ ext/ftp/tests/bug39458.phpt | 35 ++++++++++++++++++++++++++++++++++ ext/ftp/tests/server.inc | 27 ++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 ext/ftp/tests/bug39458-2.phpt create mode 100644 ext/ftp/tests/bug39458.phpt diff --git a/NEWS b/NEWS index ea37bf043c..f8e345b322 100644 --- a/NEWS +++ b/NEWS @@ -77,6 +77,7 @@ PHP NEWS number of backslashes). (David Soria Parra, Pierre) - Fixed bug #39534 (Error in maths to calculate of ZEND_MM_ALIGNED_MIN_HEADER_SIZE). (wharmby at uk dot ibm dot com, Dmitry) +- Fixed bug #39458 (ftp_nlist() returns false on empty dirs). (Nuno) - Fixed bug #39454 (Returning a SOAP array segfaults PHP). (Dmitry) - Fixed bug #39445 (Calling debug_backtrace() in the __toString() function produces a crash). (Dmitry) diff --git a/ext/ftp/tests/bug39458-2.phpt b/ext/ftp/tests/bug39458-2.phpt new file mode 100644 index 0000000000..4cd2a45236 --- /dev/null +++ b/ext/ftp/tests/bug39458-2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #39458: ftp_nlist() returns false on empty directories (other server behaviour) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +array(3) { + [0]=> + string(5) "file1" + [1]=> + string(5) "file1" + [2]=> + string(9) "file +b0rk" +} +array(0) { +} +bool(false) diff --git a/ext/ftp/tests/bug39458.phpt b/ext/ftp/tests/bug39458.phpt new file mode 100644 index 0000000000..5ea345776c --- /dev/null +++ b/ext/ftp/tests/bug39458.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #39458: ftp_nlist() returns false on empty directories +--SKIPIF-- + +--FILE-- + +--EXPECT-- +bool(true) +array(3) { + [0]=> + string(5) "file1" + [1]=> + string(5) "file1" + [2]=> + string(9) "file +b0rk" +} +array(0) { +} +bool(false) diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 7480d5c588..e08eeb438a 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -201,6 +201,33 @@ while($buf = fread($s, 4098)) { change_dir($m[1]); fputs($s, "250 CWD command successful.\r\n"); + } elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) { + + if (isset($m[1]) && $m[1] === 'bogusdir') { + fputs($s, "250 $m[1]: No such file or directory\r\n"); + continue; + } + + // there are some servers that don't open the ftp-data socket if there's nothing to send + if (isset($bug39458) && isset($m[1]) && $m[1] === 'emptydir') { + fputs($s, "226 Transfer complete.\r\n"); + continue; + } + + fputs($s, "150 File status okay; about to open data connection\r\n"); + + if (!$fs = stream_socket_client("tcp://$host:$port")) { + fputs($s, "425 Can't open data connection\r\n"); + continue; + } + + if (empty($m[1]) || $m[1] !== 'emptydir') { + fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n"); + } + + fputs($s, "226 Closing data Connection.\r\n"); + fclose($fs); + } elseif (preg_match("~^MKD ([A-Za-z./]+)\r\n$~", $buf, $m)) { if (isset($bug7216)) { fputs($s, "257 OK.\r\n"); -- 2.40.0