Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

0xced
Copy link
Collaborator

@0xced 0xced commented Jan 8, 2024

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
Copy link
Owner

manuelbl commented Jan 8, 2024

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
Copy link
Collaborator Author

0xced commented Jan 8, 2024

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.

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
Copy link
Owner

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
Copy link
Collaborator Author

0xced commented Jan 19, 2024

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
Copy link
Owner

I have merged it with minor changes to the documentation.

@manuelbl manuelbl closed this Jan 21, 2024
@0xced 0xced deleted the crlf branch January 25, 2024 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants