]> granicus.if.org Git - php/commitdiff
- #39538, fgetcsv can't handle starting newlines and trailing odd
authorPierre Joye <pajoye@php.net>
Wed, 22 Nov 2006 12:56:26 +0000 (12:56 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 22 Nov 2006 12:56:26 +0000 (12:56 +0000)
  number of backslashes (David Soria Parra, Pierre)

ext/standard/file.c
ext/standard/tests/file/bug39538.phpt [new file with mode: 0644]

index b2bed8b8a5cfd44fff62ffa51d24e63a5cc4e2ab..c933412c8c5c99b64b3756ff2170b0a0f45f9138 100644 (file)
@@ -2249,6 +2249,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, /* {{{ */
                                                                memcpy(tptr, hunk_begin, bptr - hunk_begin);
                                                                tptr += (bptr - hunk_begin);
                                                                hunk_begin = bptr;
+                                                               if (hunk_begin != line_end) {
+                                                                       memcpy(tptr, hunk_begin, bptr - hunk_begin);
+                                                                       tptr += (bptr - hunk_begin);
+                                                                       hunk_begin = bptr;
+                                                               }
 
                                                                /* add the embedded line end to the field */
                                                                memcpy(tptr, line_end, line_end_len);
diff --git a/ext/standard/tests/file/bug39538.phpt b/ext/standard/tests/file/bug39538.phpt
new file mode 100644 (file)
index 0000000..16f1523
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+bug 39538
+--FILE--
+<?php
+$content = array("\"\nthis is an test\", \"next data\", \"p\narsed\"","\"\r\nthis is an test\", \"next data\", \"p\r\narsed\"","\"\n\rthis is an test\", \"next data\", \"p\n\rarsed\"");
+
+$file = dirname(__FILE__) . "/bug39538.csv";
+@unlink($file);
+foreach ($content as $v) {
+       file_put_contents($file, $v);
+       print_r (fgetcsv(fopen($file, "r"), filesize($file)));
+}
+@unlink($file);
+--EXPECT--
+Array
+(
+    [0] => 
+this is an test
+    [1] => next data
+    [2] => p
+arsed
+)
+Array
+(
+    [0] => 
+this is an test
+    [1] => next data
+    [2] => p
+arsed
+)
+Array
+(
+    [0] => 
+
+this is an test
+    [1] => next data
+    [2] => p
+
+arsed
+)