From: Arnaud Le Blanc Date: Fri, 8 May 2009 09:49:27 +0000 (+0000) Subject: MFB5.3 fix for bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as X-Git-Tag: php-5.2.10RC1~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=78ecc1871089293a623ffab366ce3963c9fea0a0;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 df600f527e..25887fd8a6 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -788,16 +788,20 @@ 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; } if (PG(magic_quotes_runtime)) { /* s is in target_buf which is freed at the end of the function */ - slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC); + slashed = php_addslashes(s, (p-s-windows_eol), &len, 0 TSRMLS_CC); add_index_stringl(return_value, i++, slashed, len, 0); } else { - 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..0a8df3e23c --- /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)); +} +?> +--EXPECTF-- +data://text/plain,foo\r\nbar\r\n +array(2) { + [0]=> + string(3) "foo" + [1]=> + string(3) "bar" +} +data://text/plain,\r\nfoo\r\nbar\r\n +array(3) { + [0]=> + string(0) "" + [1]=> + string(3) "foo" + [2]=> + string(3) "bar" +} +data://text/plain,foo\r\nbar +array(2) { + [0]=> + string(3) "foo" + [1]=> + string(3) "bar" +}