lbarnaud Fri May 8 10:01:40 2009 UTC Added files: /php-src/ext/standard/tests/file file_variation10.phpt
Modified files: /php-src/ext/standard file.c Log: Fix default behavior of file() (FILE_TEXT flag is the default) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.544&r2=1.545&diff_format=u Index: php-src/ext/standard/file.c diff -u php-src/ext/standard/file.c:1.544 php-src/ext/standard/file.c:1.545 --- php-src/ext/standard/file.c:1.544 Fri May 8 10:00:09 2009 +++ php-src/ext/standard/file.c Fri May 8 10:01:40 2009 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.544 2009/05/08 10:00:09 lbarnaud Exp $ */ +/* $Id: file.c,v 1.545 2009/05/08 10:01:40 lbarnaud Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -779,7 +779,6 @@ /* {{{ proto array file(string filename [, int flags[, resource context]]) U Read entire file into an array */ -/* UTODO: Accept unicode contents */ PHP_FUNCTION(file) { zval **ppfilename; @@ -801,7 +800,7 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|lr!", &ppfilename, &flags, &zcontext) == FAILURE) { return; } - if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT | PHP_FILE_TEXT)) { + if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT | PHP_FILE_TEXT | PHP_FILE_BINARY)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%ld' flag is not supported", flags); RETURN_FALSE; } @@ -809,7 +808,7 @@ use_include_path = flags & PHP_FILE_USE_INCLUDE_PATH; include_new_line = !(flags & PHP_FILE_IGNORE_NEW_LINES); skip_blank_lines = flags & PHP_FILE_SKIP_EMPTY_LINES; - text_mode = flags & PHP_FILE_TEXT; + text_mode = !(flags & PHP_FILE_BINARY); context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT); if (php_stream_path_param_encode(ppfilename, &filename, &filename_len, REPORT_ERRORS, context) == FAILURE) { http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/file_variation10.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/file/file_variation10.phpt +++ php-src/ext/standard/tests/file/file_variation10.phpt --TEST-- file(): FILE_TEXT, FILE_BINARY, and default behavior --FILE-- <?php $urls = array(); $urls[] = "data://text/plain,foo\nbar\n"; $urls[] = "data://text/plain,\nfoo\nbar\n"; $urls[] = "data://text/plain,foo\nbar"; foreach($urls as $url) { echo strtr($url, array("\r" => "\\r", "\n" => "\\n")) . "\n"; var_dump(file($url, FILE_IGNORE_NEW_LINES)); var_dump(file($url, FILE_IGNORE_NEW_LINES|FILE_TEXT)); var_dump(file($url, FILE_IGNORE_NEW_LINES|FILE_BINARY)); } ?> --EXPECTF-- data://text/plain,foo\nbar\n array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } data://text/plain,\nfoo\nbar\n array(3) { [0]=> unicode(0) "" [1]=> unicode(3) "foo" [2]=> unicode(3) "bar" } array(3) { [0]=> unicode(0) "" [1]=> unicode(3) "foo" [2]=> unicode(3) "bar" } array(3) { [0]=> string(0) "" [1]=> string(3) "foo" [2]=> string(3) "bar" } data://text/plain,foo\nbar array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } array(2) { [0]=> unicode(3) "foo" [1]=> unicode(3) "bar" } array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php