1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Interwiki: Fix the bug that occurred with entries with no aliases

This commit is contained in:
Timur Ismagilov 2022-07-11 13:51:58 +05:00
parent 28001f034e
commit a4c9edd0ca

View File

@ -45,13 +45,27 @@ func addEntry(wiki *Wiki) error {
defer mutex.Unlock() defer mutex.Unlock()
var ( 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) ok, name = areNamesFree(names)
) )
if !ok { if !ok {
log.Printf("There are multiple uses of the same name %s\n", name) log.Printf("There are multiple uses of the same name %s\n", name)
return errors.New(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) listOfEntries = append(listOfEntries, wiki)
for _, name := range names { for _, name := range names {