Fix #956: Incorrectly handled backslash-escaped space characters within number formats (#957)

Backslash-escaped space characted sometimes not converted to quoted strings, so formatted string contains extra slashes.
This commit is contained in:
Aleksandr Borovikov 2019-05-30 14:37:48 +05:00 committed by Mark Baker
parent 85dfd8b00b
commit 53ac682ba7
3 changed files with 7 additions and 1 deletions

View File

@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix handling for escaped enclosures and new lines in CSV Separator Inference
- Fix MATCH an error was appearing when comparing strings against 0 (always true)
- Fix incorrectly handled backslash-escaped space characters in number format
- Fix wrong calculation of highest column with specified row [#700](https://github.com/PHPOffice/PhpSpreadsheet/issues/700)
- Fix VLOOKUP
- Fix return type hint

View File

@ -614,7 +614,7 @@ class NumberFormat extends Supervisor
}
// Convert any other escaped characters to quoted strings, e.g. (\T to "T")
$format = preg_replace('/(\\\([^ ]))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format);
$format = preg_replace('/(\\\(((.)(?!((AM\/PM)|(A\/P))))|([^ ])))(?=(?:[^"]|"[^"]*")*$)/u', '"${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);

View File

@ -88,6 +88,11 @@ return [
12345.678900000001,
'$ #,##0.000',
],
[
'12,345.679 €',
12345.678900000001,
'#,##0.000\ [$€-1]',
],
[
'5.68',
5.6788999999999996,