From 3f6d85497f6a95f297fa0b87a0556819be6e6243 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 26 May 2021 12:00:55 +0200 Subject: [PATCH] Fix error when searching for a namespace returned no results --- pkg/models/namespace.go | 4 ++++ pkg/models/namespace_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 97a6fe9ea..1192df666 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -487,6 +487,10 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int namespaceIDs, ownerIDs := getNamespaceOwnerIDs(namespaces) + if len(namespaceIDs) == 0 { + return nil, 0, 0, nil + } + subscriptionsMap, err := getNamespaceSubscriptions(s, namespaceIDs, doer.ID) if err != nil { return nil, 0, 0, err diff --git a/pkg/models/namespace_test.go b/pkg/models/namespace_test.go index 363558c18..09f6f8a51 100644 --- a/pkg/models/namespace_test.go +++ b/pkg/models/namespace_test.go @@ -346,4 +346,14 @@ func TestNamespace_ReadAll(t *testing.T) { // Assert the first namespace is not the favorites namespace assert.NotEqual(t, SavedFiltersPseudoNamespace.ID, namespaces[0].ID) }) + t.Run("no results", func(t *testing.T) { + db.LoadAndAssertFixtures(t) + s := db.NewSession() + defer s.Close() + + n := &Namespace{} + nn, _, _, err := n.ReadAll(s, user1, "some search string which will never return results", 1, -1) + assert.NoError(t, err) + assert.Nil(t, nn) + }) }