Skip to content

Commit 945b1f6

Browse files
committed
Don't allow number token to be immediately followed by a unicode letter
Fixes #651
1 parent c95354c commit 945b1f6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lexer/Tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class Tokenizer {
4646
{
4747
type: TokenType.NUMBER,
4848
regex:
49-
/(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?!\w)/uy,
49+
/(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy,
5050
},
5151
// RESERVED_PHRASE is matched before all other keyword tokens
5252
// to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause.

test/behavesLikeMariaDbFormatter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) {
5151
);
5252
});
5353

54+
// regression test for sql-formatter#651
55+
it('supports unicode identifiers that start with numbers', () => {
56+
expect(format('SELECT 1ä FROM tbl')).toBe(
57+
dedent`
58+
SELECT
59+
60+
FROM
61+
tbl
62+
`
63+
);
64+
});
65+
5466
it('supports @variables', () => {
5567
expect(format('SELECT @foo, @some_long.var$with$special.chars')).toBe(dedent`
5668
SELECT

0 commit comments

Comments
 (0)