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

[Bug]: Cannot import CSV file with specified text. #371

Closed
dawounit opened this issue Oct 19, 2023 · 4 comments
Closed

[Bug]: Cannot import CSV file with specified text. #371

dawounit opened this issue Oct 19, 2023 · 4 comments
Assignees
Labels
Milestone

Comments

@dawounit
Copy link

Expected behavior

The CSV file will be imported properly and a preview will be generated.

Actual behavior

It shows the message "Uploaded no valid preview file." instead of preview and the error "Uploaded file not valid, not creating any queue items and doing any cleanup." occurs when trying to execute import.

Steps to reproduce

Create import configuration. Select CSV as file format. Try to load file with below contents:

columnA;columnB
Some value;<a href=
@dawounit dawounit added the Bug label Oct 19, 2023
@robertSt7 robertSt7 self-assigned this Oct 27, 2023
@dvesh3 dvesh3 assigned kingjia90 and unassigned robertSt7 Oct 31, 2023
@kingjia90
Copy link
Contributor

kingjia90 commented Nov 2, 2023

Confirming the problem, it looks like finfo is confused when detecting html code

$mime = finfo_file($finfo, $path);

Thinking of a solution for this but might be a third-partyish issue

See also https://core.trac.wordpress.org/ticket/47448

confirming also that problem persist when quoting the code and set the enclosure to " or ', and is not related by the fact that the last cell is an html code (can be anywhere)

@dawounit
Copy link
Author

dawounit commented Nov 3, 2023

I think the real problem is the extension of the downloaded file. If I download the "data.csv" file, its name changes to "upload.import" after downloading on the server. This is misleading for "finfo_file" because there is no metadata in the csv file and you can only rely on the contents and extension of the file. The extension ("import") cannot match any mime type and the content contains html, so this fits best. Leaving the file extension "csv" solves this problem without having to expand the list of accepted mime types.

@kingjia90
Copy link
Contributor

kingjia90 commented Nov 3, 2023

it's a good input but i've tried to change to not change the file extension from .csv and the finfo_file still fails

More details
finfo uses unix file command, so it's at even lower level.
https://stackoverflow.com/a/45964722
image

On the opposite end, changing to symfony mime type guesser also doesn't help since
image
since is based on finfo as well https://symfony.com/doc/current/components/mime.html#guessing-the-mime-type:~:text=one%20of%20them%20based%20on%20the%20PHP%20fileinfo%20extension.

@dvesh3
Copy link
Contributor

dvesh3 commented Nov 7, 2023

Fixed by #374

@dvesh3 dvesh3 closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants