Skip to content

Commit

Permalink
Fix error with a single byte being removed after the _ spacing charac…
Browse files Browse the repository at this point in the history
…ter when rendering number formats (#1927)

* Fix error with a single byte being removed after the _ spacing character when rendering number formats
  • Loading branch information
Mark Baker authored Mar 15, 2021
1 parent 0902225 commit 9b67e3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Fixed

- Fixed issue with _ spacing character in number format mask corrumpting output from toFormattedString() [Issue 1924#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1924) [PR #1927](https://github.com/PHPOffice/PhpSpreadsheet/pull/1927)
- Fix for [Issue #1887](https://github.com/PHPOffice/PhpSpreadsheet/issues/1887) - Lose Track of Selected Cells After Save
- Fixed issue with Xlsx@listWorksheetInfo not returning any data
- Fixed invalid arguments triggering mb_substr() error in LEFT(), MID() and RIGHT() text functions. [Issue #640](https://github.com/PHPOffice/PhpSpreadsheet/issues/640)
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ function ($matches) {
);

// Convert any other escaped characters to quoted strings, e.g. (\T to "T")
$format = preg_replace('/(\\\(((.)(?!((AM\/PM)|(A\/P))))|([^ ])))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format);
$format = preg_replace('/(\\\(((.)(?!((AM\/PM)|(A\/P))))|([^ ])))(?=(?:[^"]|"[^"]*")*$)/ui', '"${2}"', $format);

// Get the sections, there can be up to four sections, separated with a semi-colon (but only if not a quoted literal)
$sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format);
Expand All @@ -857,7 +857,7 @@ function ($matches) {

// In Excel formats, "_" is used to add spacing,
// The following character indicates the size of the spacing, which we can't do in HTML, so we just use a standard space
$format = preg_replace('/_./', ' ', $format);
$format = preg_replace('/_(.)/ui', ' ${1}', $format);

// Let's begin inspecting the format and converting the value to a formatted string

Expand Down
9 changes: 7 additions & 2 deletions tests/data/Style/NumberFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
12345.678900000001,
'#,##0.000\ [$]',
],
'Spacing Character' => [
'826.00 €',
826,
'#,##0.00 _€',
],
[
'5.68',
5.6788999999999996,
Expand Down Expand Up @@ -294,12 +299,12 @@
'[$-1010409]#,##0.00;-#,##0.00',
],
[
' $ 23.06 ',
' ($ 23.06 )',
23.0597,
'_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)',
],
[
' € 13.03 ',
' (€ 13.03 )',
13.0316,
'_("€"* #,##0.00_);_("€"* \(#,##0.00\);_("€"* "-"??_);_(@_)',
],
Expand Down

0 comments on commit 9b67e3f

Please sign in to comment.