Skip to content

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