Fixed #5355 - Named variables don't work when followed by Windows CRLF line endings (#5356)

* Fixed #5355.

* Fixed unit test to test both CRLF and CR line endings
This commit is contained in:
Clark McCauley 2022-05-22 01:16:01 -06:00 committed by GitHub
parent 7496c3a56e
commit 540fb49bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -127,7 +127,7 @@ func (expr NamedExpr) Build(builder Builder) {
if v == '@' && !inName { if v == '@' && !inName {
inName = true inName = true
name = []byte{} name = []byte{}
} else if v == ' ' || v == ',' || v == ')' || v == '"' || v == '\'' || v == '`' || v == '\n' || v == ';' { } else if v == ' ' || v == ',' || v == ')' || v == '"' || v == '\'' || v == '`' || v == '\r' || v == '\n' || v == ';' {
if inName { if inName {
if nv, ok := namedMap[string(name)]; ok { if nv, ok := namedMap[string(name)]; ok {
builder.AddVar(builder, nv) builder.AddVar(builder, nv)

View File

@ -94,6 +94,16 @@ func TestNamedExpr(t *testing.T) {
Vars: []interface{}{sql.Named("name", "jinzhu")}, Vars: []interface{}{sql.Named("name", "jinzhu")},
Result: "name1 = ? AND name2 = ?;", Result: "name1 = ? AND name2 = ?;",
ExpectedVars: []interface{}{"jinzhu", "jinzhu"}, ExpectedVars: []interface{}{"jinzhu", "jinzhu"},
}, {
SQL: "name1 = @name1\r\n AND name2 = @name2",
Vars: []interface{}{map[string]interface{}{"name1": "jinzhu", "name2": "jinzhu"}},
Result: "name1 = ?\r\n AND name2 = ?",
ExpectedVars: []interface{}{"jinzhu", "jinzhu"},
}, {
SQL: "name1 = @name1\r AND name2 = @name2",
Vars: []interface{}{map[string]interface{}{"name1": "jinzhu", "name2": "jinzhu"}},
Result: "name1 = ?\r AND name2 = ?",
ExpectedVars: []interface{}{"jinzhu", "jinzhu"},
}, { }, {
SQL: "?", SQL: "?",
Vars: []interface{}{clause.Column{Table: "table", Name: "col"}}, Vars: []interface{}{clause.Column{Table: "table", Name: "col"}},