magento2: Excel writer generates invalid files for numbers that are followed by spaces
Preconditions and environment
- Magento 2.4.6
- php 8.2
Steps to reproduce
Create an instance of with an over an array containing a field with a value like (i.e. space followed by digits, read as space).Magento\Framework\Convert\ExcelArrayIterator␣123␣ Call or on the object.convertwrite Try opening the resulting file with a current version of Microsoft Excel or LibreOffice Calc. They will refuse to open the file or display for the value respectively.NaN``
Expected result
The Excel XML should encode field as a :String
<Data ss:Type="String">123 </Data>
Actual result
The value is encoded as :Number
<Data ss:Type="Number">123 </Data>
Additional information
magento2/lib/internal/Magento/Framework/Convert/Excel.php#L153
$dataType = is_numeric($value) && $value[0] !== ‘+’ && $value[0] !== ‘0’ ? ‘Number’ : ‘String’;
Release note
https://www.php.net/manual/en/migration80.incompatible.php
Numeric string handling has been altered to be more intuitive and less error-prone. Trailing whitespace is now allowed in numeric strings for consistency with how leading whitespace is treated. This mostly affects:
The is_numeric() function
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 3 months ago
- Comments: 27
Hi @chenglinag, here is your Magento Instance: https://a9d17aa366da5f17e6b6eed8624e1052.instances-prod.magento-community.engineering Admin access: https://a9d17aa366da5f17e6b6eed8624e1052.instances-prod.magento-community.engineering/admin_39d3 Login: 7dbf3180 Password: 649b313282a2