manuelbl / SwissQRBill.NET

.NET library for Swiss QR bill payment slips (aka QR-Rechnung)
MIT License
88 stars 33 forks source link

Allow QR code text using carriage return (\r) line ending #52

Closed 0xced closed 2 years ago

0xced commented 2 years ago

The Swiss Implementation Guidelines for the QR-bill explicitly forbids CR as line ending:

All data elements must be present. If the data element has no content, at least a new line must be present (CR + LF or LF, but not CR alone)

But some QR-bills were found in practice using CR as line ending. ¯_(ツ)_/¯

manuelbl commented 2 years ago

Thanks for the PR. I will look into it.

Do you have more information about the QR bills with CR only? Where did come from? Did they contain other errors?

0xced commented 2 years ago

I can't share specific details about this problematic QR-bill but I can say that apart from this CR line ending issue, the QR-bill is valid. With this pull request applied, the following code runs fine and returns a valid Bill object passing all validations:

var bill = QRBill.DecodeQrCodeText(qrCode);
var validationResult = QRBill.Validate(bill);
if (validationResult.HasErrors)
    throw new QRBillValidationException(validationResult);
return validationResult.CleanedBill;

Before this pull request DecodeQrCodeText() fails with Unknown error (data_structure_invalid) because the SplitLines method returns a single line.

Also, I learnt that a string containing CR line endings, when displayed in a task dialog, is rendered as multi-line, just like if the line endings were CRLF!