Escape double quotes in a string value unless it's an empty string value

This commit is contained in:
MarkBaker 2022-03-05 12:31:11 +01:00
parent 51453db41e
commit cba0e13b2a
3 changed files with 17 additions and 1 deletions

View File

@ -43,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
Note that this method is used when translating Excel functions between `en_us` and other locale languages, as well as when converting formulae between different spreadsheet formats (e.g. Ods to Excel).
Nor is this a perfect solution, as there may still be issues when function calls have array arguments that themselves contain function calls; but it's still better than the current logic.
- Fix for escaping double quotes within a formula [Issue #1971](https://github.com/PHPOffice/PhpSpreadsheet/issues/1971) [PR #2651](https://github.com/PHPOffice/PhpSpreadsheet/pull/2651)
## 1.22.0 - 2022-02-18

View File

@ -158,6 +158,10 @@ class Functions
if (is_bool($condition)) {
return '=' . ($condition ? 'TRUE' : 'FALSE');
} elseif (!is_numeric($condition)) {
if ($condition !== '""') { // Not an empty string
// Escape any quotes in the string value
$condition = preg_replace('/"/ui', '""', $condition);
}
$condition = Calculation::wrapResult(strtoupper($condition));
}

View File

@ -29,6 +29,18 @@ return [
'<"<A"',
'<<A',
],
[
'="A"',
'=A',
],
[
'="""A"""',
'="A"',
],
[
'="""A""B"""',
'="A"B"',
],
[
'<>"< PLEASE SELECT >"',
'<>< Please Select >',