From 862f7d38686b58d77293d9d7129cc9e96cc17c01 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 20 Jun 2024 09:10:22 +0300 Subject: [PATCH 1/2] Fix parsing of /** **/ nested block comments Fixes #747 --- src/lexer/NestedComment.ts | 4 ++-- test/features/comments.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) 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'); From 6308190dbfe13ce946b292cd9a42f645558c68a3 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 20 Jun 2024 09:22:29 +0300 Subject: [PATCH 2/2] Add Wylie Conlon to contributors list --- AUTHORS | 1 + 1 file changed, 1 insertion(+) 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