From 74321a8a8c5186cc25ad644b341ab915fe7294fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Tue, 23 Jan 2024 13:08:27 +0100 Subject: [PATCH] [FIX] formatting: do not show escape character 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. Task: 3698283 --- src/helpers/cells/cell_helpers.ts | 3 +++ tests/plugins/cell.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/helpers/cells/cell_helpers.ts b/src/helpers/cells/cell_helpers.ts index e96313a4c..fdc022ff6 100644 --- a/src/helpers/cells/cell_helpers.ts +++ b/src/helpers/cells/cell_helpers.ts @@ -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"; diff --git a/tests/plugins/cell.test.ts b/tests/plugins/cell.test.ts index c8f66416f..286079009 100644 --- a/tests/plugins/cell.test.ts +++ b/tests/plugins/cell.test.ts @@ -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", () => {