From: Arnaud Le Blanc Date: Fri, 8 May 2009 09:50:11 +0000 (+0000) Subject: MFB5.3 fix for bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as X-Git-Tag: php-5.4.0alpha1~191^2~3725 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64725cb0fc823ab85d7d111eb317802f89eb7064;p=php 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) --- diff --git a/ext/standard/file.c b/ext/standard/file.c index 5ea095de0f..4345349ddf 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -852,11 +852,15 @@ uparse_eol: } 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 @@ parse_eol: } 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)))); } diff --git a/ext/standard/tests/file/bug44034.phpt b/ext/standard/tests/file/bug44034.phpt new file mode 100644 index 0000000000..21d319731c --- /dev/null +++ b/ext/standard/tests/file/bug44034.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #44034 +--FILE-- + "\\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" +}