CSV imports keep accented letters: csvTextToUtf8 reads an upload as UTF-8 whether it was saved as UTF-8, UTF-16, Windows-1252 or Mac Roman, used by every import window kind, bank statements on Expenses and Income, and the network IP and interface imports; tab separated files import; the import answer survives a bad byte; 26.12.6 changelog and CONTRIBUTING rule

This commit is contained in:
johnnyq
2026-12-04 11:55:35 -05:00
parent 76c572c67e
commit c4e486a652
7 changed files with 92 additions and 18 deletions

View File

@@ -38,9 +38,9 @@ function expenseImportDateFormats() {
/**
* Read a statement CSV - [header (a name for each column), rows (lists of
* cells)], or null with $error. Handles a byte order mark, Windows text,
* commas, semicolons, tabs or pipes, lines before the header, and a file
* with no header at all.
* cells)], or null with $error. Handles any text the bank or spreadsheet
* saved it as (csvTextToUtf8), commas, semicolons, tabs or pipes, lines
* before the header, and a file with no header at all.
*/
function expenseImportRead($path, &$error = '') {
$error = '';
@@ -53,10 +53,7 @@ function expenseImportRead($path, &$error = '') {
$error = 'That file is too big - export a month or two at a time';
return null;
}
$text = preg_replace('/^\xEF\xBB\xBF/', '', $text);
if (!mb_check_encoding($text, 'UTF-8')) {
$text = mb_convert_encoding($text, 'UTF-8', 'Windows-1252');
}
$text = csvTextToUtf8($text);
$text = str_replace(["\r\n", "\r"], "\n", $text);
if (strpos($text, "\0") !== false) {
$error = "That doesn't look like a CSV file - export the statement as CSV";