Substitute a literal dot inside quotes within number format masks to prevent it being mistaken for a decimal separator (#1830)

* Substitute a literal dot inside quotes within number format masks to prevent it being mistaken for a decimal separator
This commit is contained in:
Mark Baker 2021-02-08 15:06:07 +01:00 committed by GitHub
parent 2fac9ee2f7
commit b068639513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed ### Fixed
- Fix problem resulting from literal dot inside quotes in number format masks. [PR #1830](https://github.com/PHPOffice/PhpSpreadsheet/pull/1830)
- Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx. [PR #1761](https://github.com/PHPOffice/PhpSpreadsheet/pull/1761) - Resolve Google Sheets Xlsx charts issue. Google Sheets uses oneCellAnchor positioning and does not include *Cache values in the exported Xlsx. [PR #1761](https://github.com/PHPOffice/PhpSpreadsheet/pull/1761)
- Fix for Xlsx Chart axis titles mapping to correct X or Y axis label when only one is present. [PR #1760](https://github.com/PHPOffice/PhpSpreadsheet/pull/1760) - Fix for Xlsx Chart axis titles mapping to correct X or Y axis label when only one is present. [PR #1760](https://github.com/PHPOffice/PhpSpreadsheet/pull/1760)
- Fix For Null Exception on ODS Read of Page Settings. [#1772](https://github.com/PHPOffice/PhpSpreadsheet/issues/1772) - Fix For Null Exception on ODS Read of Page Settings. [#1772](https://github.com/PHPOffice/PhpSpreadsheet/issues/1772)

View File

@ -833,6 +833,14 @@ class NumberFormat extends Supervisor
return $value; return $value;
} }
$format = preg_replace_callback(
'/(["])(?:(?=(\\\\?))\\2.)*?\\1/u',
function ($matches) {
return str_replace('.', chr(0x00), $matches[0]);
},
$format
);
// Convert any other escaped characters to quoted strings, e.g. (\T to "T") // 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))))|([^ ])))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format);
@ -868,6 +876,8 @@ class NumberFormat extends Supervisor
$value = $writerInstance->$function($value, $colors); $value = $writerInstance->$function($value, $colors);
} }
$value = str_replace(chr(0x00), '.', $value);
return $value; return $value;
} }

View File

@ -88,6 +88,26 @@ return [
12345.678900000001, 12345.678900000001,
'#,##0.000', '#,##0.000',
], ],
[
'12.34 kg',
12.34,
'0.00 "kg"',
],
[
'kg 12.34',
12.34,
'"kg" 0.00',
],
[
'12.34 kg.',
12.34,
'0.00 "kg."',
],
[
'kg. 12.34',
12.34,
'"kg." 0.00',
],
[ [
'£ 12,345.68', '£ 12,345.68',
12345.678900000001, 12345.678900000001,