forked from mirror/gorm
* Fixed #5355. * Fixed unit test to test both CRLF and CR line endings
This commit is contained in:
parent
7496c3a56e
commit
540fb49bcb
|
@ -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)
|
||||||
|
|
|
@ -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"}},
|
||||||
|
|
Loading…
Reference in New Issue