Skip to content
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

PhpOffice\PhpSpreadsheet\Reader\Csv::inferSeparator() generate a notice with empty file #337

Closed
Raphhh opened this issue Jan 16, 2018 · 6 comments

Comments

@Raphhh
Copy link

Raphhh commented Jan 16, 2018

This is:

- [ x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

IOFactory should load empty csv file.

What is the current behavior?

IOFactory generates a notice when we load an empty csv file.

What are the steps to reproduce?

<?php
require __DIR__ . '/vendor/autoload.php';

$filepath = __DIR__ . '/empty.csv';
touch($filepath);

\PhpOffice\PhpSpreadsheet\IOFactory::load($filepath); //PHP Notice:  Undefined offset: -1 in vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Csv.php on line 185

Which versions of PhpSpreadsheet and PHP are affected?

My env:

  • PHP:7.2.1-1+ubuntu14.04.1+deb.sury.org+1PHP
  • phpoffice/phpspreadsheet:1.0.0
@PowerKiKi
Copy link
Member

Would you submit a PR to fix that and cover it with unit tests ?

@floriandammeyer
Copy link

I encountered a similar issue when I tried to load an invalid CSV file for testing purposes using Laravel's UploadedFile::fake() method (meaning the file was not a CSV file at all but contained random bytes instead).

We have an upload form for CSV files, the uploaded files are read using PhpOffice\PhpSpreadsheet\Reader\Csv. To react to malformed files, our script relies on the canRead() method of the CSV reader. But that method only checks if the file exists, not if it is a CSV file that can be read. Therefore the script continues and runs into the same situation as stated above, a PHP Notice is emitted which is hard to react to. A ReaderException would be more helpful.

Unfortunately I do not have the time to take a deeper look into this problem myself.

@PowerKiKi
Copy link
Member

@floriandammeyer e31878c should help with your case.

@stale
Copy link

stale bot commented Apr 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2018
@stale stale bot closed this as completed Apr 24, 2018
@ricardosaracino
Copy link

im getting a separator ":" from a csv file

image

slaur pushed a commit to slaur/PhpSpreadsheet that referenced this issue Oct 26, 2018
PowerKiKi pushed a commit that referenced this issue Oct 28, 2018
guillaume-ro-fr pushed a commit to guillaume-ro-fr/PhpSpreadsheet that referenced this issue Jun 12, 2019
@oleibman
Copy link
Collaborator

oleibman commented Jul 5, 2024

Fixed by PR #743.

@oleibman oleibman removed the stale label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants