manuelbl / SwissQRBill.NET

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

Add possibility to encode the QR code text with CRLF #65

Closed 0xced closed 6 months ago

0xced commented 6 months ago

This introduces a new Separator property on the Bill object which can be either LF (the default) or CR + LF.

The Swiss Implementation Guidelines for the QR-bill (§ 4.1.4 Separator element) allows both:

The individual elements in the Swiss QR Code according to the Swiss standard are separated from one another with a carriage return. All data elements must be present. If the data element has no content, at least a new line must be present. The same type of carriage return must always be used within a document. The following carriage returns are permitted:

  • CR + LF
  • LF

Some other libraries out there manipulating the QR code data absolutely require CR + LF.

manuelbl commented 6 months ago

Thanks for your contribution.

"Some other libraries out there": What specific libraries are these? (I'd like to understand the motivation for this feature.)

0xced commented 6 months ago

The culprit is the FastReport .NET library. It assumes CRLF separators when given a Swiss QR-bill code and does something roughly equivalent to this:

var parts = qrCodeText.Split("\r\n");
var iban = parts[3]; // 👈 crashes with IndexOutOfRangeException

It should be using a StreamReader but unfortunately does not!

I have reported this issue to the FastReport support today so we can probably wait a bit and see if they fix their QR data decoder.

manuelbl commented 6 months ago

Have you heard back re FastReport.NET?

I'm currently working on a new release. But it's delayed because I lost my access to the QR bill validator portal and SIX is not responding.

0xced commented 6 months ago

Support said it's now in the hands of the development team but that's it for now.

Note that I have updated the code since my initial pull request and force pushed. It's now using a StringWriter instead of a StringBuilder and the code is tidy. Since the QR-bill spec allows both LF and CR+LF I think it makes sense to propose both possibilities, defaulting to the existing (LF) behaviour.

manuelbl commented 6 months ago

I have merged it with minor changes to the documentation.