Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of /** **/ nested block comments #751

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ Toliver <[email protected]>
Toni Müller <[email protected]>
Tyler Jones <[email protected]>
Uku Pattak <[email protected]>
Wylie Conlon <[email protected]>
Xin Hu <[email protected]>
Zhongxian Liang <[email protected]>
4 changes: 2 additions & 2 deletions src/lexer/NestedComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: */

/**
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/features/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down