]> granicus.if.org Git - php/commitdiff
tests + BFN
authorNuno Lopes <nlopess@php.net>
Fri, 1 Dec 2006 16:37:39 +0000 (16:37 +0000)
committerNuno Lopes <nlopess@php.net>
Fri, 1 Dec 2006 16:37:39 +0000 (16:37 +0000)
NEWS
ext/ftp/tests/bug39458-2.phpt [new file with mode: 0644]
ext/ftp/tests/bug39458.phpt [new file with mode: 0644]
ext/ftp/tests/server.inc

diff --git a/NEWS b/NEWS
index ea37bf043cea080ac57b474ba72a0bc984cef246..f8e345b3226d4453f2694c198aa34de555bab4e8 100644 (file)
--- 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 (file)
index 0000000..4cd2a45
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories (other server behaviour)
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug39458=1;
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--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 (file)
index 0000000..5ea3457
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--EXPECT--
+bool(true)
+array(3) {
+  [0]=>
+  string(5) "file1"
+  [1]=>
+  string(5) "file1"
+  [2]=>
+  string(9) "file
+b0rk"
+}
+array(0) {
+}
+bool(false)
index 7480d5c588d7357ffaba3bbe62c19523deb58ce2..e08eeb438aa5dd3f2df5f40d7c4f24716181c2e9 100644 (file)
@@ -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");