Skip to content

Commit

Permalink
Fix case where mergeComplexNumberFormatMasks would get stuck in endle…
Browse files Browse the repository at this point in the history
…ss-loop (#1793)

* Fix case where mergeComplexNumberFormatMasks would get stuck in endless-loop if $numbers had many decimals
  • Loading branch information
brainz80 authored Feb 8, 2021
1 parent b068639 commit f60f37c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PhpSpreadsheet/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,11 @@ private static function mergeComplexNumberFormatMasks($numbers, $masks)

do {
$tempMask = array_pop($masks);
$postDecimalMasks[] = $tempMask;
$decimalCount -= strlen($tempMask);
} while ($decimalCount > 0);
if ($tempMask !== null) {
$postDecimalMasks[] = $tempMask;
$decimalCount -= strlen($tempMask);
}
} while ($tempMask !== null && $decimalCount > 0);

return [
implode('.', $masks),
Expand Down
20 changes: 20 additions & 0 deletions tests/data/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,24 @@
25,
'[Green][<>25]"<>25 green";[Red]"else red"',
],
[
'pfx. 25.00',
25,
'"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;',
],
[
'pfx. 25.20',
25.2,
'"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;',
],
[
'pfx. -25.20',
-25.2,
'"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;',
],
[
'pfx. 25.26',
25.255555555555555,
'"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;',
],
];

0 comments on commit f60f37c

Please sign in to comment.