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 #2255

Task: 3215464
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
rrahir committed Mar 28, 2023
1 parent f51b30b commit b95a7ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/helpers/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*%)?$/;

Expand Down
17 changes: 16 additions & 1 deletion tests/formulas/tokenizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "=" },
Expand Down

0 comments on commit b95a7ed

Please sign in to comment.