fix(editability): allow digit-leading unquoted table names
This commit is contained in:
5 files changed
+179
-11
No files matched your search
@@ -748,7 +748,28 @@ function readIdentifier(text: string, start: number): { value: string; quoted: b
|
||||
return null;
|
||||
}
|
||||
const match = text.slice(pos).match(/^[\p{ID_Start}_][\p{ID_Continue}$]*/u);
|
||||
return match ? { value: match[0], quoted: false, end: pos + match[0].length } : null;
|
||||
if (match) return { value: match[0], quoted: false, end: pos + match[0].length };
|
||||
// MySQL/MariaDB also allow an unquoted identifier to begin with a digit as long as it is not a
|
||||
// pure number, so `select * from 01_tablename` maps back to a base table while `123` / `1e3`
|
||||
// stay literals (#9992).
|
||||
const digitMatch = text.slice(pos).match(/^[0-9][\p{ID_Continue}$]*/u);
|
||||
if (digitMatch && !isNumberShapedToken(digitMatch[0])) {
|
||||
return { value: digitMatch[0], quoted: false, end: pos + digitMatch[0].length };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors `sqlNavigation.isNumberShapedToken`: a digit-leading token is only an identifier when
|
||||
* it is not a number (`123`, `1e3`, `0x1f`, `0b101`). See #9992.
|
||||
*/
|
||||
function isNumberShapedToken(value: string): boolean {
|
||||
if (!/^[0-9]/.test(value)) return false;
|
||||
const rest = value.slice(1).toLowerCase();
|
||||
if (rest === "") return true;
|
||||
if (rest.startsWith("x")) return /^x[0-9a-f]+$/.test(rest);
|
||||
if (rest.startsWith("b")) return /^b[01]+$/.test(rest);
|
||||
return /^[0-9e]+$/.test(rest);
|
||||
}
|
||||
|
||||
function skipWhitespace(text: string, pos: number): number {
|
||||
|
||||
Reference in new issue
Block a user