From d03afd173f5e0192ea6a9c6991634e0c87d8ea97 Mon Sep 17 00:00:00 2001 From: Tino Diaz Date: Sun, 26 Mar 2017 14:00:34 +0100 Subject: [PATCH] Fix empty string as order clause --- query_test.go | 5 +++++ search.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/query_test.go b/query_test.go index 866d81d2..9531b33e 100644 --- a/query_test.go +++ b/query_test.go @@ -360,6 +360,11 @@ func TestOrderAndPluck(t *testing.T) { t.Errorf("Order with multiple orders") } + var ages6 []int64 + if err := scopedb.Order("").Pluck("age", &ages6).Error; err != nil { + t.Errorf("An empty string as order clause produces invalid queries") + } + DB.Model(User{}).Select("name, age").Find(&[]User{}) } diff --git a/search.go b/search.go index 8a4f4df6..23dac2c3 100644 --- a/search.go +++ b/search.go @@ -67,7 +67,7 @@ func (s *search) Order(value interface{}, reorder ...bool) *search { s.orders = []interface{}{} } - if value != nil { + if value != nil && value != "" { s.orders = append(s.orders, value) } return s