From c14870c5ac52bf9d2d8b884222b4743accf9d929 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 11 May 2018 16:15:18 +0800 Subject: [PATCH] fix blank topic (#3948) --- public/js/index.js | 4 ++++ routers/repo/topic.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index 000229dbc..e826c2f3f 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2197,7 +2197,11 @@ function initTopicbar() { alert(res.message); } else { viewDiv.children(".topic").remove(); + if (topics.length == 0) { + return + } var topicArray = topics.split(","); + var last = viewDiv.children("a").last(); for (var i=0;i < topicArray.length; i++) { $('
'+topicArray[i]+'
').insertBefore(last) diff --git a/routers/repo/topic.go b/routers/repo/topic.go index 90ef0d189..2a43d53ff 100644 --- a/routers/repo/topic.go +++ b/routers/repo/topic.go @@ -21,7 +21,11 @@ func TopicPost(ctx *context.Context) { return } - topics := strings.Split(ctx.Query("topics"), ",") + var topics = make([]string, 0) + var topicsStr = strings.TrimSpace(ctx.Query("topics")) + if len(topicsStr) > 0 { + topics = strings.Split(topicsStr, ",") + } err := models.SaveTopics(ctx.Repo.Repository.ID, topics...) if err != nil {