svenstaro / mt940-rs

A MT940 parser in Rust
MIT License
22 stars 7 forks source link

UnknownTagError when tag 86 details contains colon #51

Closed markus-k closed 2 years ago

markus-k commented 2 years ago

First of all: I'm not an expert at all on MT940, so this may be a problem with an invalid MT940 statement, but I'm not sure.

Parsing an MT940 statement fails, when the details following tag 86 contain a colon (e.g. from a time). For example this modified statement from the tests, containing a time:

:20:STARTUMSE
:25:20752041/0291593375
:28C:00000/001
:60F:C181126EUR13564,13
:61:1811271127DR119,35NDDTNONREF
:86:basically some information here
lots of information
then some
:61:1811271127DR16,69NDDTNONREF
:86:Lorem ipsum dolor sit amet, consetetur sadipscing elitr, seda
diam nonumy eirmod tempor invidunt ut labore et dolore magna alda
quyam erat, sed diam voluptua. At vero eos et accusam et justo da
uo dolores et ea rebum. 20:44:45 clita kasd gubergren, no sea tak
a sanctus est Lorem ipsum dolor sit amet.
:61:1811271127DR5,00N033NONREF
:86:a lot of information again
very important indeed
but totally conformant
however, some ümläuté and öther stüff för some rëäsön
which the bank didn't escape
:62F:C181127EUR13523,09

Parsing this statement fails with:

UnknownTagError("44")

Code used to parse it:

let input = to_swift_charset(&input);
let input = strip_stuff_between_messages(&input);

let parsed = parse_mt940(&input).unwrap();

Thank you for any input on this!

svenstaro commented 2 years ago

Hmmm yeah this seems to be a bug indeed depending on who you ask. The spec I used is here from Deutsche Bank and they define x as alphanumeric. However, another field spec is defined here and it seems to be 6*65x where x is defined here.

svenstaro commented 2 years ago

I did some more research on this and while : seems like a valid character, I couldn't find a single example except for yours. I'll try to fix the bug and add your example to the test base.

svenstaro commented 2 years ago

Should be fixed now, thanks for the report!

markus-k commented 2 years ago

Thank you! My bank statements finally parse correctly.

My banks mt940 are full of colons in the details, e.g.:

:86:106?00Kartenzahlung girocard?10xxx?20EREF+xxxxxxxxxxxxxxx
?27SVWZ+DAS ERDGESCHOSS GIR 69?28xxxxxxx/HAMBURG/DE          
?29     xx.01.2022 um 22:44:35?30WELAXXXXXXX
?31DExxxxx0000000xxxxxxx?32DAS ERDGESCHOSS?xxxxx