Skip to content

Commit

Permalink
[FIX] tokenizer: detect xc with sheet name starting with a number
Browse files Browse the repository at this point in the history
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 #2281

Task: 3215464
X-original-commit: fdbbcf2
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
rrahir committed Mar 29, 2023
1 parent 8c89731 commit a7e221f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/formulas/tokenizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit a7e221f

Please sign in to comment.