Skip to content

Commit

Permalink
Fix single line comment for line endings in mac when sanitizing.
Browse files Browse the repository at this point in the history
  • Loading branch information
psyhatter authored and jackc committed Mar 5, 2022
1 parent b6b24f9 commit a86ece0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/sanitize/sanitize.go
Expand Up @@ -246,7 +246,7 @@ func oneLineCommentState(l *sqlLexer) stateFn {
case '\\':
_, width = utf8.DecodeRuneInString(l.src[l.pos:])
l.pos += width
case '\n':
case '\n', '\r':
return rawState
case utf8.RuneError:
if l.pos-l.start > 0 {
Expand Down
12 changes: 8 additions & 4 deletions internal/sanitize/sanitize_test.go
Expand Up @@ -77,12 +77,16 @@ func TestNewQuery(t *testing.T) {
expected: sanitize.Query{Parts: []sanitize.Part{"select -- a baby's toy\n'barbie', ", 1}},
},
{
sql: "select 42 -- is a Thinker's favorite number",
expected: sanitize.Query{Parts: []sanitize.Part{"select 42 -- is a Thinker's favorite number"}},
sql: "select 42 -- is a Deep Thought's favorite number",
expected: sanitize.Query{Parts: []sanitize.Part{"select 42 -- is a Deep Thought's favorite number"}},
},
{
sql: "select 42, -- \\nis a Thinker's favorite number\n$1",
expected: sanitize.Query{Parts: []sanitize.Part{"select 42, -- \\nis a Thinker's favorite number\n", 1}},
sql: "select 42, -- \\nis a Deep Thought's favorite number\n$1",
expected: sanitize.Query{Parts: []sanitize.Part{"select 42, -- \\nis a Deep Thought's favorite number\n", 1}},
},
{
sql: "select 42, -- \\nis a Deep Thought's favorite number\r$1",
expected: sanitize.Query{Parts: []sanitize.Part{"select 42, -- \\nis a Deep Thought's favorite number\r", 1}},
},
}

Expand Down

0 comments on commit a86ece0

Please sign in to comment.