]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as
authorIlia Alshanetsky <iliaa@php.net>
Tue, 15 Apr 2008 15:48:20 +0000 (15:48 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 15 Apr 2008 15:48:20 +0000 (15:48 +0000)
expected when lines end in \r\n)

NEWS
ext/standard/file.c

diff --git a/NEWS b/NEWS
index 0ee8a8b6020764f81caf0b6f37d20ab75ed82f0e..5130a49569aed8997344aba53fd687d4018ebf22 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -158,6 +158,8 @@ PHP                                                                        NEWS
   (Derick, iuri dot fiedoruk at hp dot com).
 - Fixed bug #44214 (Crash using preg_replace_callback() and global variable).
   (Nuno, Scott)
+- Fixed bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as expected
+  when lines end in \r\n). (Ilia)
 - Fixed bug #43960 (strtotime() returns timestamp in the future when given a
   bogus string). (Derick)
 - Fixed bug #43832 (mysqli_get_charset() doesn't expose charset comment).
index 38d2a1e34ff02fd5fe5df28d41715e5b19082379..5a782d6da60a8d2f7e18a6ca00b17a66253b4e6b 100644 (file)
@@ -775,16 +775,20 @@ parse_eol:
                        } while ((p = 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;
                                }
                                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))));