Skip to content

Commit b0e07e0

Browse files
authored
Fix parsing of /** **/ nested block comments (#751)
Don't try to be too clever with matching lots of characters with that funky MIDDLE regex. Just match a single char. Fixes #747
2 parents 7aee250 + 6308190 commit b0e07e0

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ Toliver <[email protected]>
5151
Toni Müller <[email protected]>
5252
Tyler Jones <[email protected]>
5353
Uku Pattak <[email protected]>
54+
Wylie Conlon <[email protected]>
5455
5556
Zhongxian Liang <[email protected]>

src/lexer/NestedComment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { RegExpLike } from './TokenizerEngine.js';
33

44
const START = /\/\*/uy; // matches: /*
5-
const MIDDLE = /([^/*]|\*[^/]|\/[^*])+/uy; // matches text NOT containing /* or */
5+
const ANY_CHAR = /[\s\S]/uy; // matches single character
66
const END = /\*\//uy; // matches: */
77

88
/**
@@ -31,7 +31,7 @@ export class NestedComment implements RegExpLike {
3131
} else if ((match = this.matchSection(END, input))) {
3232
result += match;
3333
nestLevel--;
34-
} else if ((match = this.matchSection(MIDDLE, input))) {
34+
} else if ((match = this.matchSection(ANY_CHAR, input))) {
3535
result += match;
3636
} else {
3737
return null;

test/features/comments.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ export default function supportsComments(format: FormatFn, opts: CommentsConfig
239239
`);
240240
});
241241

242+
// Regression test for #747
243+
it('handles block comments with /** and **/ patterns', () => {
244+
const sql = `/** This is a block comment **/`;
245+
expect(format(sql)).toBe(sql);
246+
});
247+
242248
if (opts.hashComments) {
243249
it('supports # line comment', () => {
244250
const result = format('SELECT alpha # commment\nFROM beta');

0 commit comments

Comments
 (0)