Skip to content

Commit

Permalink
Fix bugs #46900 and #46903.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinf committed Dec 28, 2008
1 parent 78505f8 commit c5a0027
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 14 deletions.
4 changes: 3 additions & 1 deletion main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 16 additions & 0 deletions tests/output/bug46900.phpt
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/output/bug46903.phpt
Original file line number Diff line number Diff line change
@@ -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
20 changes: 14 additions & 6 deletions tests/output/ob_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
17 changes: 14 additions & 3 deletions tests/output/ob_015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 0 additions & 2 deletions tests/output/ob_start_basic_002.phpt
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions tests/output/ob_start_basic_004.phpt
Original file line number Diff line number Diff line change
@@ -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
/*
Expand Down

0 comments on commit c5a0027

Please sign in to comment.