Skip to content

Commit e0a7cf4

Browse files
committed
Add "@" to operators list to ensure we don't crash on it
1 parent ff7f201 commit e0a7cf4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/core/Tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class Tokenizer {
7777
cfg.reservedJoinConditions,
7878
specialWordCharsAll
7979
),
80-
[TokenType.OPERATOR]: regexFactory.createOperatorRegex('+-/*%&|^><=.,;[]{}`:$', [
80+
[TokenType.OPERATOR]: regexFactory.createOperatorRegex('+-/*%&|^><=.,;[]{}`:$@', [
8181
'<>',
8282
'<=',
8383
'>=',

test/sql.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,19 @@ describe('StandardSqlFormatter', () => {
5454
2 ROWS ONLY;
5555
`);
5656
});
57+
58+
// This is a crappy behavior, but at least we don't crash
59+
it('does not crash when encountering characters or operators it does not recognize', () => {
60+
expect(
61+
format(`
62+
SELECT @name, :bar FROM {foo};
63+
`)
64+
).toBe(dedent`
65+
SELECT
66+
@ name,
67+
: bar
68+
FROM
69+
{foo};
70+
`);
71+
});
5772
});

0 commit comments

Comments
 (0)