Skip to content

Commit

Permalink
[FIX] formatting: do not show escape character
Browse files Browse the repository at this point in the history
If you want to use double quotes in a string which is part of a formula, you
have to escape it using a backslash (="hello \"world\"")
However, the backslash is shown when displaying the cell content.

closes #3497

Task: 3698283
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
  • Loading branch information
LucasLefevre committed Jan 29, 2024
1 parent 6944f99 commit 88ea76d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/helpers/cells/cell_helpers.ts
Expand Up @@ -10,6 +10,9 @@ import { formatNumber, formatStandardNumber } from "../numbers";
export function formatValue(value: CellValue, format?: string): string {
switch (typeof value) {
case "string":
if (value.includes('\\"')) {
return value.replace(/\\"/g, '"');
}
return value;
case "boolean":
return value ? "TRUE" : "FALSE";
Expand Down
6 changes: 6 additions & 0 deletions tests/plugins/cell.test.ts
Expand Up @@ -62,6 +62,12 @@ describe("getCellText", () => {
});
expect(result).toBeCancelledBecause(CommandResult.TargetOutOfSheet);
});

test("escape character is not display when formatting string", () => {
const model = new Model();
setCellContent(model, "A1", '="hello \\"world\\""');
expect(getCell(model, "A1")?.formattedValue).toBe('hello "world"');
});
});

describe("link cell", () => {
Expand Down

0 comments on commit 88ea76d

Please sign in to comment.