lbarnaud Fri May 8 09:50:11 2009 UTC Modified files: /php-src/ext/standard file.c /php-src/ext/standard/tests/file bug44034.phpt Log: MFB5.3 fix for bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as expected when lines end in \r\n) (fixes #48175) http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.542&r2=1.543&diff_format=u Index: php-src/ext/standard/file.c diff -u php-src/ext/standard/file.c:1.542 php-src/ext/standard/file.c:1.543 --- php-src/ext/standard/file.c:1.542 Sun Apr 19 17:09:46 2009 +++ php-src/ext/standard/file.c Fri May 8 09:50:11 2009 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.542 2009/04/19 17:09:46 lbarnaud Exp $ */ +/* $Id: file.c,v 1.543 2009/05/08 09:50:11 lbarnaud Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -852,11 +852,15 @@ } while ((p = u_memchr(p, eol_marker, (e-p)))); } else { do { - if (skip_blank_lines && !(p-s)) { + int windows_eol = 0; + if (eol_marker == '\n' && *(p - 1) == '\r') { + windows_eol++; + } + if (skip_blank_lines && !(p-s-windows_eol)) { s = ++p; continue; } - add_index_unicodel(return_value, i++, eustrndup(s, p-s), p-s, 0); + add_index_unicodel(return_value, i++, eustrndup(s, p-s-windows_eol), p-s-windows_eol, 0); s = ++p; } while ((p = u_memchr(p, eol_marker, (e-p)))); } @@ -889,11 +893,15 @@ } while ((p = memchr(p, eol_marker, (e-p)))); } else { do { - if (skip_blank_lines && !(p-s)) { + int windows_eol = 0; + if (p != target_buf && eol_marker == '\n' && *(p - 1) == '\r') { + windows_eol++; + } + if (skip_blank_lines && !(p-s-windows_eol)) { s = ++p; continue; } - add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); + add_index_stringl(return_value, i++, estrndup(s, p-s-windows_eol), p-s-windows_eol, 0); s = ++p; } while ((p = memchr(p, eol_marker, (e-p)))); } http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/bug44034.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/standard/tests/file/bug44034.phpt diff -u /dev/null php-src/ext/standard/tests/file/bug44034.phpt:1.2 --- /dev/null Fri May 8 09:50:11 2009 +++ php-src/ext/standard/tests/file/bug44034.phpt Fri May 8 09:50:11 2009 @@ -0,0 +1,39 @@ +--TEST-- +Bug #44034 +--FILE-- +<?php + +$urls = array(); +$urls[] = "data://text/plain,foo\r\nbar\r\n"; +$urls[] = "data://text/plain,\r\nfoo\r\nbar\r\n"; +$urls[] = "data://text/plain,foo\r\nbar"; + +foreach($urls as $url) { + echo strtr($url, array("\r" => "\\r", "\n" => "\\n")) . "\n"; + var_dump(file($url, FILE_IGNORE_NEW_LINES|FILE_TEXT)); +} +?> +--EXPECTF-- +data://text/plain,foo\r\nbar\r\n +array(2) { + [0]=> + %unicode|string%(3) "foo" + [1]=> + %unicode|string%(3) "bar" +} +data://text/plain,\r\nfoo\r\nbar\r\n +array(3) { + [0]=> + %unicode|string%(0) "" + [1]=> + %unicode|string%(3) "foo" + [2]=> + %unicode|string%(3) "bar" +} +data://text/plain,foo\r\nbar +array(2) { + [0]=> + %unicode|string%(3) "foo" + [1]=> + %unicode|string%(3) "bar" +}
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php