Skip to content
Snippets Groups Projects
Unverified Commit a6056bd6 authored by Ariya Hidayat's avatar Ariya Hidayat Committed by GitHub
Browse files

Custom expression suggestion: tackle a dangling single/double quote (#19033)

If the expression is invalid due to an unterminated string (perhaps the
user is still not finished typing the expression), do not try to suggest
possible matches (functions etc) for an identifier following that
dangling quote.
parent e46db354
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,13 @@ export function partialMatch(expression) {
const lastToken = _.last(tokens);
if (lastToken && lastToken.type === TOKEN.Identifier) {
if (lastToken.end === expression.length) {
const prevToken = tokens[tokens.length - 2];
if (prevToken && prevToken.type === TOKEN.String) {
if (prevToken.start + 1 === prevToken.end) {
// a dangling single- or double-quote
return null;
}
}
return expression.slice(lastToken.start, lastToken.end);
}
}
......
......@@ -28,6 +28,11 @@ describe("metabase/lib/expressions/completer", () => {
expect(partialMatch("")).toEqual(null);
expect(partialMatch(" ")).toEqual(null);
});
it("should handle a dangling quote", () => {
expect(partialMatch("concat('s")).toEqual(null);
expect(partialMatch('length("c')).toEqual(null);
});
});
describe("enclosingFunction", () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment