Fix single line comment for line endings in mac when sanitizing.

pull/1172/head
Andrew Rusakow 2022-03-02 19:46:39 +07:00 committed by Jack Christensen
parent b6b24f9e8a
commit a86ece025c
2 changed files with 9 additions and 5 deletions

View File

@ -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 {

View File

@ -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}},
},
}