You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even selecting the correct columns in the interface, I get the exception Unable to encode attribute [data] for model [Filament\Actions\Imports\Models\FailedImportRow] to JSON: Malformed UTF-8 characters, possibly incorrectly encoded.
Also, I noticed that the row data has the same issue. The expected output should be Conceição instead of Conceio.
In this case, for test purposes, I am able to fix the row data by updating the method Filament\Actions\Imports\Jobs\ImportCsv::utf8Encode from
if (is_string($value)) {
return mb_convert_encoding($value, 'UTF-8', 'UTF-8');
}
to
if (is_string($value)) {
return mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
}
But the title column remains with the issue and I am not able to import.
Other than that, I converted my test file to UTF-8 (iconv -f ISO-8859-1 -t utf-8 input-ISO-8859-1.csv -o input-utf8.csv) and it works as expected.
Expected behavior
I expect that the Filament handles CSV files that are not encoded with UTF-8.
Steps to reproduce
Create an import action
Update the getColumns method and add the method guess()
Upload a CSV file encoded with ISO-8859-1 (there is an example in the reproduction repository called input-ISO-8859-1.csv in the project's root). At least one title should have a character like ç, í and ã.
However, the input encoding would have to be set dynamically. This function doesn't seem to work, as of PHP8.1, to automatically detect encoding. Maybe a dropdown with possible encodings could be presented to the user instead?
Maybe instead of a dropdown with possible encodings presented to the user, it could be an option in the Importer class with the expected charsets and using the function mb_detect_encoding to detect the most likely character encoding.
Package
filament/actions
Package Version
v3.2.60
Laravel Version
v10.48.4
Livewire Version
v3.4.9
PHP Version
PHP 8.3.3
Problem description
When I try to import a CSV file encoded with ISO-8859-1, the columns are not mapped although I set up it in the getColumns method.
Even selecting the correct columns in the interface, I get the exception
Unable to encode attribute [data] for model [Filament\Actions\Imports\Models\FailedImportRow] to JSON: Malformed UTF-8 characters, possibly incorrectly encoded.
Also, I noticed that the row data has the same issue. The expected output should be
Conceição
instead ofConceio
.In this case, for test purposes, I am able to fix the row data by updating the method Filament\Actions\Imports\Jobs\ImportCsv::utf8Encode from
to
But the title column remains with the issue and I am not able to import.
Other than that, I converted my test file to UTF-8 (
iconv -f ISO-8859-1 -t utf-8 input-ISO-8859-1.csv -o input-utf8.csv
) and it works as expected.Expected behavior
I expect that the Filament handles CSV files that are not encoded with UTF-8.
Steps to reproduce
guess()
input-ISO-8859-1.csv
in the project's root). At least one title should have a character likeç
,í
andã
.Reproduction repository
https://github.com/Rahmon/filamentphp-issues
Relevant log output
The text was updated successfully, but these errors were encountered: