]> granicus.if.org Git - php/commitdiff
Fix bugs #46900 and #46903.
authorRobin Fernandes <robinf@php.net>
Sun, 28 Dec 2008 19:50:58 +0000 (19:50 +0000)
committerRobin Fernandes <robinf@php.net>
Sun, 28 Dec 2008 19:50:58 +0000 (19:50 +0000)
main/output.c
tests/output/bug46900.phpt [new file with mode: 0644]
tests/output/bug46903.phpt [new file with mode: 0644]
tests/output/ob_014.phpt
tests/output/ob_015.phpt
tests/output/ob_start_basic_002.phpt
tests/output/ob_start_basic_004.phpt

index 5a2b8641d39a2e440a4f0645f5b3c0cf8c1d2aee..c5c49c78735b3e8d9faa9a3da0472f385687fabc 100644 (file)
@@ -983,7 +983,7 @@ static inline php_output_handler_status_t php_output_handler_op(php_output_handl
                        ZVAL_LONG(ob_mode, (long) context->op);
                        zend_fcall_info_argn(&handler->func.user->fci TSRMLS_CC, 2, &ob_data, &ob_mode);
                        
-#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && (Z_TYPE_P(retval) != IS_NULL) && (Z_TYPE_P(retval) != IS_BOOL || Z_BVAL_P(retval)))
+#define PHP_OUTPUT_USER_SUCCESS(retval) (retval && !(Z_TYPE_P(retval) == IS_BOOL && Z_BVAL_P(retval)==0))
                        if (SUCCESS == zend_fcall_info_call(&handler->func.user->fci, &handler->func.user->fcc, &retval, NULL TSRMLS_CC) && PHP_OUTPUT_USER_SUCCESS(retval)) {
                                /* user handler may have returned TRUE */
                                status = PHP_OUTPUT_HANDLER_NO_DATA;
@@ -1342,6 +1342,8 @@ PHP_FUNCTION(ob_start)
        }
        if (chunk_size < 0) {
                chunk_size = 0;
+       } else if (chunk_size == 1) {
+               chunk_size = 4096;
        }
        
        if (SUCCESS != php_output_start_user(output_handler, chunk_size, flags TSRMLS_CC)) {
diff --git a/tests/output/bug46900.phpt b/tests/output/bug46900.phpt
new file mode 100644 (file)
index 0000000..42f65e4
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #46900 (Unexpected behaviour in HEAD when output buffer callback returns null)
+--FILE--
+<?php
+function return_null($string) {
+       return null;
+}
+
+ob_start('return_null');
+echo "You shouldn't see this.\n";
+ob_end_flush();
+
+echo 'done';
+?>
+--EXPECTF--
+done
\ No newline at end of file
diff --git a/tests/output/bug46903.phpt b/tests/output/bug46903.phpt
new file mode 100644 (file)
index 0000000..c0933d2
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #46903 (ob_start(): Special $chunk_size value of 1 is not honoured in HEAD)
+--FILE--
+<?php
+function flushCounter($input) {
+       static $counter=0;
+       return '[' . ++$counter . "] $input \n";
+}
+
+// This should set the buffer size to 4096
+ob_start('flushCounter', 1);
+
+// Get the buffer size: 
+$bufferInfo = ob_get_status(true);
+var_dump($bufferInfo[0]['chunk_size']);
+
+// If the buffer size is >1, these two chars should
+// come out as part of a single flush:
+echo "1";
+echo "2";
+?>
+--EXPECTF--
+[1] int(4096)
+12 
\ No newline at end of file
index 03980c2dd91a2628f5f528841c07e5db6ec20461..8454e7d53497808751b61f862f4435d1068f81b0 100644 (file)
@@ -2,13 +2,21 @@
 output buffering - failure
 --FILE--
 <?php
-/*
- * apparently the error handler cannot get the current function name on shutdown
- */
 ob_start("str_rot13");
 echo "foo\n";
+// str_rot13 expects 1 param and returns NULL when passed 2 params.
+// It is invoked with 2 params when used as an OB callback.
+// Therefore, there will be no data in the buffer. This is expected: see bug 46900.
+ob_end_flush();
+
+// Show the error.
+print_r(error_get_last());
 ?>
 --EXPECTF--
-foo
-
-Warning: (null)() expects exactly 1 parameter, 2 given in %s on line %d
+Array
+(
+    [type] => 2
+    [message] => str_rot13() expects exactly 1 parameter, 2 given
+    [file] => %s
+    [line] => 7
+)
\ No newline at end of file
index 6454fcd2e59d42b25fe24d971004ddd45e3f2da9..4de45396d802f4e1a85cf6233442396cc12380e4 100644 (file)
@@ -4,8 +4,19 @@ output buffering - failure
 <?php
 ob_start("str_rot13", 1);
 echo "foo\n";
+// str_rot13 expects 1 param and returns NULL when passed 2 params.
+// It is invoked with 2 params when used as an OB callback.
+// Therefore, there will be no data in the buffer. This is expected: see bug 46900.
+ob_end_flush();
+
+// Show the error.
+print_r(error_get_last());
 ?>
 --EXPECTF--
-foo
-
-Warning: str_rot13() expects exactly 1 parameter, 2 given in %s on line %d
+Array
+(
+    [type] => 2
+    [message] => str_rot13() expects exactly 1 parameter, 2 given
+    [file] => %s
+    [line] => 7
+)
\ No newline at end of file
index 3ed5b6ebd1836b51bcc07c1a65fb1edc2a53a428..92d9069f32ff98df088616593e8e66c135ba95b8 100644 (file)
@@ -1,7 +1,5 @@
 --TEST--
 ob_start(): Check behaviour with various callback return values.
---XFAIL--
-PHP6 behaves differently from PHP5 when callback returns null. See bug 46900.
 --FILE--
 <?php
 function return_empty_string($string) {
index 505cd9e14a11fc96b386058bba9c40d8cc673ff2..39d3aadc49e87f1c51767f10366a1713907c9b37 100644 (file)
@@ -1,7 +1,5 @@
 --TEST--
 ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size.
---XFAIL--
-Special behaviour when chunk_size set to 1 is not honoured on PHP6. See bug 46903.
 --FILE--
 <?php
 /*