stephanstapel / ZUGFeRD-csharp

C# assembly for creating and reading ZUGFeRD invoices
Apache License 2.0
165 stars 87 forks source link

FacturX date fields with CR LF and space Characters #342

Closed cedricnotin closed 4 days ago

cedricnotin commented 5 days ago

Hi, We discovered a library malfunction in a very specific case. We have received a PDF invoice file from another software which contains a facturx.xml file inside. When we try to parse the XML file with the library, an exception is thrown :

System.Exception : 'Wrong length of datetime element (format 102)'
s2industries.ZUGFeRD.XmlUtils.NodeAsDateTime(System.Xml.XmlNode, string, System.Xml.XmlNamespaceManager, System.DateTime?) dans XmlUtils.cs
    s2industries.ZUGFeRD.InvoiceDescriptor22CIIReader.Load(System.IO.Stream) dans InvoiceDescriptor22CIIReader.cs 

While analyzing the file, we discovered a strange value in date fields. All date fields contain spaces and LF characters.

  <ram:IssueDateTime>
    <udt:DateTimeString format="102">
      20240806
    </udt:DateTimeString>
  </ram:IssueDateTime>

We have checked the file with fnfe-mpe.org validator, and the file appears to be correct. In the Factur-X specification, there is no information about these characters.

In my opinion, the emitter software should be fixed. But I'm not sure they'll do it on their end. So to protect this, I suggest adding this code in XmlUtils.cs / NodeAsDateTime. rawValue = rawValue.Trim();.

I'll create a PR for that, and on the other hand, I will contact emitter software developper for asking to request a fix.

What do you think ?

Best Regards

cedricnotin commented 5 days ago

https://github.com/stephanstapel/ZUGFeRD-csharp/pull/343

stephanstapel commented 4 days ago

real world is often different from the specs, pull request merged.

cedricnotin commented 4 days ago

You're right :) Thanks you.