From b95a7ed21b28c43016169fa01f8530f78d229b31 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#2255 Task: 3215464 Signed-off-by: Lucas Lefèvre (lul) --- src/helpers/numbers.ts | 2 +- tests/formulas/tokenizer.test.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/helpers/numbers.ts b/src/helpers/numbers.ts index 889e60d000..d0742e0852 100644 --- a/src/helpers/numbers.ts +++ b/src/helpers/numbers.ts @@ -7,7 +7,7 @@ * - it does not accept "," as thousand separator, because when we tokenize a * formula, commas are used to separate arguments */ -export const formulaNumberRegexp = /^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?/; +export const formulaNumberRegexp = /(^-?\d+(\.?\d*(e\d+)?)?(\s*%)?|^-?\.\d+(\s*%)?)(?!\w|!)/; export const numberRegexp = /^-?\d+(,\d+)*(\.?\d*(e\d+)?)?(\s*%)?$|^-?\.\d+(\s*%)?$/; diff --git a/tests/formulas/tokenizer.test.ts b/tests/formulas/tokenizer.test.ts index d17efc9a22..7236a1e1b6 100644 --- a/tests/formulas/tokenizer.test.ts +++ b/tests/formulas/tokenizer.test.ts @@ -157,7 +157,22 @@ describe("tokenizer", () => { { type: "OPERATOR", value: "=" }, { type: "SYMBOL", value: "'a '' b'!A1" }, ]); - + expect(tokenize("=1name!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "SYMBOL", value: "1name!A1" }, + ]); + expect(tokenize("=123!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "SYMBOL", value: "123!A1" }, + ]); + expect(tokenize("='1name'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "SYMBOL", value: "'1name'!A1" }, + ]); + expect(tokenize("='123'!A1")).toEqual([ + { type: "OPERATOR", value: "=" }, + { type: "SYMBOL", value: "'123'!A1" }, + ]); // note the missing ' in the following test: expect(tokenize("='Sheet1!A1")).toEqual([ { type: "OPERATOR", value: "=" },