From a4c9edd0cad9f207055d9e9280f96da3618e8454 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Mon, 11 Jul 2022 13:51:58 +0500 Subject: [PATCH] Interwiki: Fix the bug that occurred with entries with no aliases --- interwiki/interwiki.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/interwiki/interwiki.go b/interwiki/interwiki.go index 519a5d6..6e2ef36 100644 --- a/interwiki/interwiki.go +++ b/interwiki/interwiki.go @@ -45,13 +45,27 @@ func addEntry(wiki *Wiki) error { defer mutex.Unlock() var ( - names = append(wiki.Aliases, wiki.Name) + // non-empty names only + names = func(names []string) []string { + var result []string + for _, name := range names { + if name != "" { + result = append(result, name) + } + } + return result + }(append(wiki.Aliases, wiki.Name)) ok, name = areNamesFree(names) ) if !ok { log.Printf("There are multiple uses of the same name ā€˜%sā€™\n", name) return errors.New(name) } + if len(names) == 0 { + log.Println("No names passed for a new interwiki entry") + // There is something clearly wrong with error-returning in this function. + return errors.New("") + } listOfEntries = append(listOfEntries, wiki) for _, name := range names {