sadpandajoe commented on code in PR #45407:
URL: https://github.com/apache/superset/pull/45407#discussion_r4364160785
##########
superset/utils/excel_streaming.py:
##########
@@ -58,9 +58,12 @@ def _quote_if_formula(text: str) -> str:
Prefix formula-like text with an apostrophe so spreadsheet apps treat it as
literal text (defense against formula injection).
- Leading whitespace is ignored when detecting a formula, because spreadsheet
- apps still evaluate a cell whose formula prefix is preceded by spaces or
- tabs (e.g. ``" =cmd"`` or ``"\\t=cmd"``).
+ Leading whitespace is stripped before the prefix is read, so ``" =cmd"`` is
+ quoted like ``"=cmd"``. Every string goes out through ``write_string``, so
Review Comment:
The new text says every string goes out through `write_string`, but headers
and data rows are written with `worksheet.write_row` (lines 190 and 202), which
does type detection, so a string starting with `=` would become a formula cell
if it were not quoted first. As written, a future reader could conclude the
quote here is optional and drop it. Could this say the quote is what keeps
`write_row` from creating formula cells, rather than claiming the writer never
produces one?
##########
tests/unit_tests/utils/excel_tests.py:
##########
@@ -80,6 +80,47 @@ def test_quote_formulas() -> None:
]
+def test_quote_formulas_with_leading_whitespace() -> None:
+ """
+ Formulas are quoted even when a space, tab, or newline comes first.
+
+ Spreadsheet apps still evaluate a cell whose formula prefix is preceded by
Review Comment:
This docstring still says spreadsheet apps evaluate a cell whose formula
prefix follows whitespace, which is the claim the source docstrings were just
corrected to drop: XlsxWriter writes these as plain string cells either way. A
reader of this test would take it as a guard against live formula execution
rather than an export-consistency check. Could the wording match the corrected
`_quote_formula` docstring?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]