diff --git a/AUTHORS b/AUTHORS index a9aea56e4a..9c729c7fd6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -51,5 +51,6 @@ Toliver Toni Müller Tyler Jones Uku Pattak +Wylie Conlon Xin Hu Zhongxian Liang diff --git a/src/lexer/NestedComment.ts b/src/lexer/NestedComment.ts index 983f0e3f28..f69b47a241 100644 --- a/src/lexer/NestedComment.ts +++ b/src/lexer/NestedComment.ts @@ -2,7 +2,7 @@ import { RegExpLike } from './TokenizerEngine.js'; const START = /\/\*/uy; // matches: /* -const MIDDLE = /([^/*]|\*[^/]|\/[^*])+/uy; // matches text NOT containing /* or */ +const ANY_CHAR = /[\s\S]/uy; // matches single character const END = /\*\//uy; // matches: */ /** @@ -31,7 +31,7 @@ export class NestedComment implements RegExpLike { } else if ((match = this.matchSection(END, input))) { result += match; nestLevel--; - } else if ((match = this.matchSection(MIDDLE, input))) { + } else if ((match = this.matchSection(ANY_CHAR, input))) { result += match; } else { return null; diff --git a/test/features/comments.ts b/test/features/comments.ts index 47b51ac957..3cb57070ec 100644 --- a/test/features/comments.ts +++ b/test/features/comments.ts @@ -239,6 +239,12 @@ export default function supportsComments(format: FormatFn, opts: CommentsConfig `); }); + // Regression test for #747 + it('handles block comments with /** and **/ patterns', () => { + const sql = `/** This is a block comment **/`; + expect(format(sql)).toBe(sql); + }); + if (opts.hashComments) { it('supports # line comment', () => { const result = format('SELECT alpha # commment\nFROM beta');