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

Most upvoted comments