Skip to content

Get Us Closer to Csv Not Autodetect By Default #4256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ class Csv extends BaseReader
*/
private static $constructorCallback;

/** Will be changed to false in next major release */
public const DEFAULT_TEST_AUTODETECT = true;

/**
* Attempt autodetect line endings (deprecated after PHP8.1)?
*/
private bool $testAutodetect = true;
private bool $testAutodetect = self::DEFAULT_TEST_AUTODETECT;

protected bool $castFormattedNumberToNumeric = false;

Expand Down
5 changes: 5 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Csv/CsvLineEndingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class CsvLineEndingTest extends TestCase
{
private string $tempFile = '';

private static bool $alwaysFalse = false;

protected function tearDown(): void
{
if ($this->tempFile !== '') {
Expand All @@ -32,6 +34,9 @@ public function testEndings(string $ending): void
$data = ['123', '456', '789'];
file_put_contents($filename, implode($ending, $data));
$reader = new Csv();
if (Csv::DEFAULT_TEST_AUTODETECT === self::$alwaysFalse) {
$reader->setTestAutoDetect(true);
}
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertEquals($data[0], $sheet->getCell('A1')->getValue());
Expand Down