Skip to content

Commit b8961a2

Browse files
committed
[FIX] composer: prevent autocomplete on unknown characters in composer
Before this commit, the composer incorrectly triggered autocomplete suggestions even when unknown or special characters (e.g., "é") were typed. This led to irrelevant suggestions and formula errors when selecting an option. This commit ensures that unknown characters are properly considered, preventing autocomplete from being triggered in such cases, improving the reliability of the function autocomplete. closes #6134 Task: 4652661 X-original-commit: 1beed80 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Signed-off-by: Mehdi Rachico (mera) <mera@odoo.com>
1 parent f5451bb commit b8961a2

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/formulas/tokenizer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ function tokenizeString(chars: TokenizingChars): Token | null {
152152
return null;
153153
}
154154

155+
/**
156+
- \p{L} is for any letter (from any language)
157+
- \p{N} is for any number
158+
- the u flag at the end is for unicode, which enables the `\p{...}` syntax
159+
*/
160+
const unicodeSymbolCharRegexp = /\p{L}|\p{N}|_|\.|!|\$/u;
155161
const SYMBOL_CHARS = new Set("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.!$");
156162

157163
/**
@@ -193,7 +199,10 @@ function tokenizeSymbol(chars: TokenizingChars): Token | null {
193199
};
194200
}
195201
}
196-
while (chars.current && SYMBOL_CHARS.has(chars.current)) {
202+
while (
203+
chars.current &&
204+
(SYMBOL_CHARS.has(chars.current) || chars.current.match(unicodeSymbolCharRegexp))
205+
) {
197206
result += chars.shift();
198207
}
199208
if (result.length) {

tests/composer/composer_integration_component.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ describe("Composer interactions", () => {
155155
expect(fixture.querySelector(".o-popover .o-autocomplete-dropdown")).toBeNull();
156156
});
157157

158+
test("autocomplete disappears when there is no match with an unknown character", async () => {
159+
await typeInComposerGrid("=éSUM");
160+
await nextTick();
161+
expect(fixture.querySelector(".o-grid .o-autocomplete-dropdown")).toBeNull();
162+
});
163+
164+
test("autocomplete disappear when typing an unknown character", async () => {
165+
await typeInComposerGrid("=SéSUM");
166+
await nextTick();
167+
expect(fixture.querySelector(".o-grid .o-autocomplete-dropdown")).toBeNull();
168+
});
169+
158170
test("focus top bar composer does not resize grid composer when autocomplete is displayed", async () => {
159171
await keyDown({ key: "Enter" });
160172
const topBarComposer = document.querySelector(".o-spreadsheet-topbar .o-composer")!;

tests/evaluation/tokenizer.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,38 @@ describe("tokenizer", () => {
287287
]);
288288
});
289289

290-
test("Unknown characters", () => {
290+
test("non-ascii characters", () => {
291291
expect(tokenize("=ù4")).toEqual([
292292
{ type: "OPERATOR", value: "=" },
293-
{ type: "UNKNOWN", value: "ù" },
293+
{ type: "SYMBOL", value: "ù4" },
294+
]);
295+
expect(tokenize("=jai_nommé_mon_range")).toEqual([
296+
{ type: "OPERATOR", value: "=" },
297+
{ type: "SYMBOL", value: "jai_nommé_mon_range" },
298+
]);
299+
expect(tokenize("=ßabc123")).toEqual([
300+
{ type: "OPERATOR", value: "=" },
301+
{ type: "SYMBOL", value: "ßabc123" },
302+
]);
303+
expect(tokenize("=ぁ72")).toEqual([
304+
{ type: "OPERATOR", value: "=" },
305+
{ type: "SYMBOL", value: "ぁ72" },
306+
]);
307+
expect(tokenize("=ñôtÁFñ(5, wr_öñg) + šymbøl +4")).toEqual([
308+
{ type: "OPERATOR", value: "=" },
309+
{ type: "SYMBOL", value: "ñôtÁFñ" },
310+
{ type: "LEFT_PAREN", value: "(" },
311+
{ type: "NUMBER", value: "5" },
312+
{ type: "ARG_SEPARATOR", value: "," },
313+
{ type: "SPACE", value: " " },
314+
{ type: "SYMBOL", value: "wr_öñg" },
315+
{ type: "RIGHT_PAREN", value: ")" },
316+
{ type: "SPACE", value: " " },
317+
{ type: "OPERATOR", value: "+" },
318+
{ type: "SPACE", value: " " },
319+
{ type: "SYMBOL", value: "šymbøl" },
320+
{ type: "SPACE", value: " " },
321+
{ type: "OPERATOR", value: "+" },
294322
{ type: "NUMBER", value: "4" },
295323
]);
296324
});

0 commit comments

Comments
 (0)