order by null is not escaped

This commit is contained in:
fanwei
2021-11-26 10:38:50 +08:00
parent 9105590c69
commit 1725d247ae
2 changed files with 18 additions and 1 deletions

View File

@ -276,6 +276,7 @@ func doQuoteWord(s, charLeft, charRight string) string {
// doQuoteString quotes string with quote chars.
// For example, if quote char is '`':
// "null" => "NULL"
// "user" => "`user`"
// "user u" => "`user` u"
// "user,user_detail" => "`user`,`user_detail`"
@ -289,7 +290,11 @@ func doQuoteString(s, charLeft, charRight string) string {
array2 := gstr.SplitAndTrim(v1, " ")
array3 := gstr.Split(gstr.Trim(array2[0]), ".")
if len(array3) == 1 {
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
if strings.EqualFold(array3[0], "NULL") {
array3[0] = doQuoteWord(array3[0], "", "")
} else {
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
}
} else if len(array3) >= 2 {
array3[0] = doQuoteWord(array3[0], charLeft, charRight)
// Note:

View File

@ -1085,6 +1085,18 @@ func Test_Model_OrderBy(t *testing.T) {
})
}
func Test_Model_OrderBy_Null(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
result, err := db.Model(table).Order("NULL").All()
t.AssertNil(err)
t.Assert(len(result), TableSize)
t.Assert(result[0]["nickname"].String(), "name_1")
})
}
func Test_Model_GroupBy(t *testing.T) {
table := createInitTable()
defer dropTable(table)