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

Start new line if \r and dialect is postgres #6

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

hansott
Copy link
Member

@hansott hansott commented Jan 8, 2025

Currently the tokenizer throws an error for

insert into cats_2 (petname) values ('foo'),--\r(version()||'\n');

this is because postgres treats \r as a separate new line character, see https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l

In order to make the world safe for Windows and Mac clients as well as Unix ones, we accept either \n or \r as a newline.
A DOS-style \r\n sequence will be seen as two successive newlines, but that doesn't cause any problems.
non_newline [^\n\r]
comment ("--"{non_newline}*)

Let's make sure we start a new line if we encounter a \r when tokenizing a comment.

Currently the tokenizer throws an error for

```sql
insert into cats_2 (petname) values ('foo'),--\r(version()||'\n');
```

this is because postgres treats \r as a separate new line character, see https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l

> In order to make the world safe for Windows and Mac clients as well as Unix ones, we accept either \n or \r as a newline.
> A DOS-style \r\n sequence will be seen as two successive newlines, but that doesn't cause any problems.
> non_newline			[^\n\r]
> comment			("--"{non_newline}*)

Let's make sure we start a new line if we encounter a \r when tokenizing a comment.
@willem-delbare willem-delbare merged commit 182dc31 into main Jan 8, 2025
18 of 20 checks passed
@hansott hansott deleted the carriage-return branch January 8, 2025 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants