]> granicus.if.org Git - php/commitdiff
- Tests and small parsing correction for php://fd wrapper
authorGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 11 Dec 2010 02:08:02 +0000 (02:08 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 11 Dec 2010 02:08:02 +0000 (02:08 +0000)
ext/standard/php_fopen_wrapper.c
ext/standard/tests/file/php_fd_wrapper_01.phpt [new file with mode: 0644]
ext/standard/tests/file/php_fd_wrapper_02.phpt [new file with mode: 0644]
ext/standard/tests/file/php_fd_wrapper_03.phpt [new file with mode: 0644]
ext/standard/tests/file/php_fd_wrapper_04.phpt [new file with mode: 0644]

index 2a7a2793c703a8d3f86b70b67f7eef647db8d336..790c06277e88e027d79e362c842f160d6d1bc455 100644 (file)
@@ -265,7 +265,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
 
                start = &path[3];
                fildes_ori = strtol(start, &end, 10);
-               if (end == start || (*end != '\0' && *end != '/')) {
+               if (end == start || *end != '\0') {
                        php_stream_wrapper_log_error(wrapper, options TSRMLS_CC,
                                "php://fd/ stream must be specified in the form php://fd/<orig fd>");
                        return NULL;
diff --git a/ext/standard/tests/file/php_fd_wrapper_01.phpt b/ext/standard/tests/file/php_fd_wrapper_01.phpt
new file mode 100644 (file)
index 0000000..037edd7
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+php://fd wrapper: basic test
+--FILE--
+<?php
+$f = fopen("php://fd/1", "wb");
+fwrite($f, "hi!");
+
+echo "\nDone.\n";
+--EXPECT--
+hi!
+Done.
diff --git a/ext/standard/tests/file/php_fd_wrapper_02.phpt b/ext/standard/tests/file/php_fd_wrapper_02.phpt
new file mode 100644 (file)
index 0000000..6d40dc9
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+php://fd wrapper: mode is ignored
+--FILE--
+<?php
+$f = fopen("php://fd/1", "rkkk");
+fwrite($f, "hi!");
+
+echo "\nDone.\n";
+--EXPECT--
+hi!
+Done.
diff --git a/ext/standard/tests/file/php_fd_wrapper_03.phpt b/ext/standard/tests/file/php_fd_wrapper_03.phpt
new file mode 100644 (file)
index 0000000..c004a43
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+php://fd wrapper: bad syntax
+--FILE--
+<?php
+fopen("php://fd", "w");
+fopen("php://fd/", "w");
+fopen("php://fd/-2", "w");
+fopen("php://fd/1/", "w");
+
+echo "\nDone.\n";
+--EXPECTF--
+Warning: fopen(): Invalid php:// URL specified in %s on line %d
+
+Warning: fopen(php://fd): failed to open stream: operation failed in %s on line 2
+
+Warning: fopen(php://fd/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
+
+Warning: fopen(php://fd/-2): failed to open stream: The file descriptors must be non-negative numbers smaller than %d in %s on line %d
+
+Warning: fopen(php://fd/1/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
+
+Done.
diff --git a/ext/standard/tests/file/php_fd_wrapper_04.phpt b/ext/standard/tests/file/php_fd_wrapper_04.phpt
new file mode 100644 (file)
index 0000000..51f4d9f
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+php://fd wrapper: invalid file descriptor
+--SKIPIF--
+<?php include('skipif.inc'); 
+if(substr(PHP_OS, 0, 3) == "WIN")
+       die("skip Not for Windows");
+
+//we'd need a release and a test variation for windows, because in debug builds we get this message:
+//Warning: Invalid parameter detected in CRT function '_dup' (f:\dd\vctools\crt_bld\self_x86\crt\src\dup.c:52)
+//I greped the CRT sources and found no function capable of validating a file descriptor
+
+--FILE--
+<?php
+fopen("php://fd/12", "w");
+
+echo "\nDone.\n";
+--EXPECTF--
+Warning: fopen(php://fd/12): failed to open stream: Error duping file descriptor 12; possibly it doesn't exist: [9]: %s in %s on line %d
+
+Done.