From a7e221fe13a1362cdf10544df5ac41f804491647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Tue, 21 Mar 2023 22:12:30 +0000 Subject: [PATCH] [FIX] tokenizer: detect xc with sheet name starting with a number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tokenizer would interpret the sheet name starting by a number as a number token, preventing it to be detected as a proper symbol. closes odoo/o-spreadsheet#2281 Task: 3215464 X-original-commit: fdbbcf22ad40176879edee13bba232ed5bb627c3 Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Rémi Rahir (rar) --- src/helpers/numbers.ts | 2 +- tests/formulas/tokenizer.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helpers/numbers.ts b/src/helpers/numbers.ts index 0b3a677bab..43061a1933 100644 --- a/src/helpers/numbers.ts +++ b/src/helpers/numbers.ts @@ -8,7 +8,7 @@ * formula, commas are used to separate arguments * - it does not support % symbol, in formulas % is an operator */ -export const formulaNumberRegexp = /^-?\d+(\.?\d*(e\d+)?)?|^-?\.\d+/; +export const formulaNumberRegexp = /(^-?\d+(\.?\d*(e\d+)?)?|^-?\.\d+)(?!\w|!)/; const pIntegerAndDecimals = "(\\d+(,\\d{3,})*(\\.\\d*)?)"; // pattern that match integer number with or without decimal digits const pOnlyDecimals = "(\\.\\d+)"; // pattern that match only expression with decimal digits diff --git a/tests/formulas/tokenizer.test.ts b/tests/formulas/tokenizer.test.ts index 05c4240c75..45ac00b81e 100644 --- a/tests/formulas/tokenizer.test.ts +++ b/tests/formulas/tokenizer.test.ts @@ -208,6 +208,22 @@ describe("tokenizer", () => { { type: "OPERATOR", value: "=" }, { type: "REFERENCE", value: "'a '' b'!A1" }, ]); + expect(tokenize("=1name!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "1name!A1" }, + ]); + expect(tokenize("=123!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "123!A1" }, + ]); + expect(tokenize("='1name'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "'1name'!A1" }, + ]); + expect(tokenize("='123'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "REFERENCE", value: "'123'!A1" }, + ]); }); test("wrong references", () => {