I noticed that xlsx_consumer.cpp throws exceptions in multiple cases when count does not match the number of elements. This causes issues because:
- According to ECMA-376, in each of these cases, the "count" attribute is optional:
<xsd:attribute name="count" type="xsd:unsignedInt" use="optional"/>
- I noticed issues when trying to open files exported by SAP software, where the exporter sets
count="1" but the actual count is 2. Of course this is wrong and is actually an issue of the SAP software - however, Microsoft Excel is still able to open the file correctly. For users of our software, it looks like our software is broken because it cannot open the file (while Excel can), since users do not know that the SAP software is actually the broken one 😅 On the other hand, while it is not nice to accept obviously broken files, there is no actual disadvantage for XLNT to simply ignore the fact that the count does not match.
My proposed solution:
- Check whether the "count" attribute exists - if it does, read it.
- If the count is known, call
std::vector::reserve to allocate enough memory right away (small performance improvement, because why not?).
- Ignore exceptions due to invalid count by default. However, if
THROW_ON_INVALID_XML is defined and the count is known, throw an exception, just like before. In other words, if a very strict XML parser is desired, exceptions can still be enabled.
I will send a pull request containing the proposed changes.
I noticed that
xlsx_consumer.cppthrows exceptions in multiple cases whencountdoes not match the number of elements. This causes issues because:count="1"but the actual count is 2. Of course this is wrong and is actually an issue of the SAP software - however, Microsoft Excel is still able to open the file correctly. For users of our software, it looks like our software is broken because it cannot open the file (while Excel can), since users do not know that the SAP software is actually the broken one 😅 On the other hand, while it is not nice to accept obviously broken files, there is no actual disadvantage for XLNT to simply ignore the fact that the count does not match.My proposed solution:
std::vector::reserveto allocate enough memory right away (small performance improvement, because why not?).THROW_ON_INVALID_XMLis defined and the count is known, throw an exception, just like before. In other words, if a very strict XML parser is desired, exceptions can still be enabled.I will send a pull request containing the proposed changes.