Skip to content

1.50: encoding rule is ignored when csv rules file is input file #2465

Description

@paul-dest

hledger 1.50.1, linux-x86_64 on Ubuntu 22.04.5 LTS

Trying to
hledger import csv.comdirectGiro.rules --dry
results in

hledger: Error: ././import/comdirectGiro/umsaetze_XXXXXXXXXX_20250924-0909.csv: hGetContents: invalid argument (cannot decode byte sequence starting from 228)
Some text could not be decoded with the system text encoding, UTF-8.
Please either convert the text to this encoding,
or configure a system locale which can decode this text.

Same with hledger -f csv.comdirectGiro.rules print.

In contrast to that, doing the same with version 1.43.2
~/hledger-linux-x64/hledger import csv.comdirectGiro.rules --dry
results as expected in

hledger: Error: could not parse "Alter Kontostand" as a date using date format "%d.%m.%Y"
record: Alter Kontostand,1.665,70 EUR,
the date rule is:   %Buchungstag
the date-format is: %d.%m.%Y
you may need to change your date rule, change your date-format rule, or change your skip rule
for m/d/y or d/m/y dates, use date-format %-m/%-d/%Y or date-format %-d/%-m/%Y

The rules file sets the encoding explicitly to iso-8859-15. Contents of csv.comdirectGiro.rules:

source ./import/comdirectGiro/umsaetze_XXXXXXXXXX*.csv
encoding	iso-8859-15
separator	;
skip		3
date-format	%d.%m.%Y
decimal-mark	,
fields		Buchungstag,Valuta,Vorgang,Buchungstext,Umsatz
date		%Buchungstag
account1	assets:eur:comdirect Giro
amount		%Umsatz EUR

if
%Buchungstext ^Auftraggeber: (.*) Buchungstext: .*
%Buchungstext ^Empfänger: (.*) Buchungstext: .*
%Buchungstext ^Buchungstext: (.*) Karte Nr..*
  description \1

if %Valuta ^(..).(..).(....)$
  comment1	date: \3-\2-\1\nvorgang: %Vorgang\nwhat: %Buchungstext

locale

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=

The error message of 1.50.1 "cannot decode byte sequence starting from 228" looks misleading to me as in file umsaetze_XXXXXXXXXX_20250924-0909.csv, there are only ASCII characters on and around position 228. The file contains some German characters äÜü, but on positions way before and way after position 228.

Furthermore, it is not understandable why hledger seemingly tries to decode the file as UTF-8 ("Some text could not be decoded with the system text encoding, UTF-8.") as the rules files sets the encoding explicitly to iso-8859-15.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BUGSomething wrong, confusing or sub-standard in the software, docs, or user experience.affects4-manyAffects potentially a significant number of users.annoyance4-majorMajor usability/doc bug, or any regression or crash.csvThe csv file format, csv output format, or generally CSV-related.i18nInternationalisation/localisation-related.regressionA backwards step, indicating a weakness in our QA. We don't like these.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions