summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2006-12-01 16:37:39 +0000
committerNuno Lopes <nlopess@php.net>2006-12-01 16:37:39 +0000
commite65bdffab503c973319c2cb460b782f3f2628752 (patch)
tree9db93c87d9d99b25e60e7e39c0fb74fd070782e4 /ext/ftp
parent8e0cf441646af567924633452cdbd1af782cdaff (diff)
downloadphp-git-e65bdffab503c973319c2cb460b782f3f2628752.tar.gz
tests + BFN
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/tests/bug39458-2.phpt36
-rw-r--r--ext/ftp/tests/bug39458.phpt35
-rw-r--r--ext/ftp/tests/server.inc27
3 files changed, 98 insertions, 0 deletions
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--
+<?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
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--
+<?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)
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");