xref: /PHP-8.4/ext/standard/tests/file/bug39538.phpt (revision f756b96e)
1--TEST--
2Bug #39538 (fgetcsv can't handle starting newlines and trailing odd number of backslashes)
3--FILE--
4<?php
5
6$file = __DIR__ . "/bug39538.csv";
7
8$line = "\"\nthis is a test\", \"next data\", \"p\narsed\"";
9$expectation = [
10    "\nthis is a test",
11    "next data",
12    "p\narsed",
13];
14
15file_put_contents($file, $line);
16$parsed_content = fgetcsv(fopen($file, "r"), filesize($file), escape: "\\");
17var_dump($parsed_content === $expectation);
18
19@unlink($file);
20
21$line = "\"\r\nthis is a test\", \"next data\", \"p\r\narsed\"";
22$expectation = [
23    "\r\nthis is a test",
24    "next data",
25    "p\r\narsed",
26];
27
28file_put_contents($file, $line);
29$parsed_content = fgetcsv(fopen($file, "r"), filesize($file), escape: "\\");
30var_dump($parsed_content === $expectation);
31
32@unlink($file);
33
34$line = "\"\n\rthis is a test\", \"next data\", \"p\n\rarsed\"";
35$expectation = [
36    "\n\rthis is a test",
37    "next data",
38    "p\n\rarsed",
39];
40
41file_put_contents($file, $line);
42$parsed_content = fgetcsv(fopen($file, "r"), filesize($file), escape: "\\");
43var_dump($parsed_content === $expectation);
44
45?>
46--CLEAN--
47<?php
48$file = __DIR__ . "/bug39538.csv";
49@unlink($file);
50?>
51--EXPECT--
52bool(true)
53bool(true)
54bool(true)
55