Escape double quotes in worksheet names for column range and row range references
This commit is contained in:
parent
23e207ccb4
commit
02c6e8cfa8
|
|
@ -4203,7 +4203,7 @@ class Calculation
|
||||||
$expectingOperator = false;
|
$expectingOperator = false;
|
||||||
}
|
}
|
||||||
$stack->push('Brace', '(');
|
$stack->push('Brace', '(');
|
||||||
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $val, $matches)) {
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $val, $matches)) {
|
||||||
// Watch for this case-change when modifying to allow cell references in different worksheets...
|
// Watch for this case-change when modifying to allow cell references in different worksheets...
|
||||||
// Should only be applied to the actual cell column, not the worksheet name
|
// Should only be applied to the actual cell column, not the worksheet name
|
||||||
// If the last entry on the stack was a : operator, then we have a cell range reference
|
// If the last entry on the stack was a : operator, then we have a cell range reference
|
||||||
|
|
@ -4326,6 +4326,8 @@ class Calculation
|
||||||
$val = $rowRangeReference[1];
|
$val = $rowRangeReference[1];
|
||||||
$length = strlen($rowRangeReference[1]);
|
$length = strlen($rowRangeReference[1]);
|
||||||
$stackItemType = 'Row Reference';
|
$stackItemType = 'Row Reference';
|
||||||
|
// unescape any apostrophes or double quotes in worksheet name
|
||||||
|
$val = str_replace(["''", '""'], ["'", '"'], $val);
|
||||||
$column = 'A';
|
$column = 'A';
|
||||||
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
|
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
|
||||||
$column = $pCellParent->getHighestDataColumn($val);
|
$column = $pCellParent->getHighestDataColumn($val);
|
||||||
|
|
@ -4338,6 +4340,8 @@ class Calculation
|
||||||
$val = $columnRangeReference[1];
|
$val = $columnRangeReference[1];
|
||||||
$length = strlen($val);
|
$length = strlen($val);
|
||||||
$stackItemType = 'Column Reference';
|
$stackItemType = 'Column Reference';
|
||||||
|
// unescape any apostrophes or double quotes in worksheet name
|
||||||
|
$val = str_replace(["''", '""'], ["'", '"'], $val);
|
||||||
$row = '1';
|
$row = '1';
|
||||||
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
|
if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
|
||||||
$row = $pCellParent->getHighestDataRow($val);
|
$row = $pCellParent->getHighestDataRow($val);
|
||||||
|
|
|
||||||
|
|
@ -176,8 +176,8 @@ class ParseFormulaTest extends TestCase
|
||||||
],
|
],
|
||||||
'Combined Cell Reference and Column Range with quote' => [
|
'Combined Cell Reference and Column Range with quote' => [
|
||||||
[
|
[
|
||||||
['type' => 'Column Reference', 'value' => "'Mark''s sheet1'!A1", 'reference' => "'Mark''s sheet1'!A1"],
|
['type' => 'Column Reference', 'value' => "'Mark's sheet1'!A1", 'reference' => "'Mark's sheet1'!A1"],
|
||||||
['type' => 'Column Reference', 'value' => "'Mark''s sheet1'!A1048576", 'reference' => "'Mark''s sheet1'!A1048576"],
|
['type' => 'Column Reference', 'value' => "'Mark's sheet1'!A1048576", 'reference' => "'Mark's sheet1'!A1048576"],
|
||||||
['type' => 'Binary Operator', 'value' => ':', 'reference' => null],
|
['type' => 'Binary Operator', 'value' => ':', 'reference' => null],
|
||||||
['type' => 'Operand Count for Function MIN()', 'value' => 1, 'reference' => null],
|
['type' => 'Operand Count for Function MIN()', 'value' => 1, 'reference' => null],
|
||||||
['type' => 'Function', 'value' => 'MIN(', 'reference' => null],
|
['type' => 'Function', 'value' => 'MIN(', 'reference' => null],
|
||||||
|
|
@ -213,8 +213,8 @@ class ParseFormulaTest extends TestCase
|
||||||
'Combined Column Range and Cell Reference with quote' => [
|
'Combined Column Range and Cell Reference with quote' => [
|
||||||
[
|
[
|
||||||
['type' => 'Cell Reference', 'value' => "'Mark's sheet1'!A1", 'reference' => "'Mark's sheet1'!A1"],
|
['type' => 'Cell Reference', 'value' => "'Mark's sheet1'!A1", 'reference' => "'Mark's sheet1'!A1"],
|
||||||
['type' => 'Column Reference', 'value' => "'Mark''s sheet1'!A1", 'reference' => "'Mark''s sheet1'!A1"],
|
['type' => 'Column Reference', 'value' => "'Mark's sheet1'!A1", 'reference' => "'Mark's sheet1'!A1"],
|
||||||
['type' => 'Column Reference', 'value' => "'Mark''s sheet1'!A1048576", 'reference' => "'Mark''s sheet1'!A1048576"],
|
['type' => 'Column Reference', 'value' => "'Mark's sheet1'!A1048576", 'reference' => "'Mark's sheet1'!A1048576"],
|
||||||
['type' => 'Binary Operator', 'value' => ':', 'reference' => null],
|
['type' => 'Binary Operator', 'value' => ':', 'reference' => null],
|
||||||
['type' => 'Operand Count for Function MIN()', 'value' => 1, 'reference' => null],
|
['type' => 'Operand Count for Function MIN()', 'value' => 1, 'reference' => null],
|
||||||
['type' => 'Function', 'value' => 'MIN(', 'reference' => null],
|
['type' => 'Function', 'value' => 'MIN(', 'reference' => null],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue