This commit is contained in:
Lunny Xiao 2018-06-15 14:08:10 +00:00 committed by GitHub
commit d18a9ada45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -6,6 +6,7 @@ package models
import (
"fmt"
"html/template"
"strings"
"code.gitea.io/gitea/modules/util"
@ -95,6 +96,10 @@ func FindTopics(opts *FindTopicOptions) (topics []*Topic, err error) {
return topics, sess.Desc("topic.repo_count").Find(&topics)
}
func validTopic(topicName string) string {
return strings.TrimSpace(template.HTMLEscapeString(template.JSEscapeString(topicName)))
}
// SaveTopics save topics to a repository
func SaveTopics(repoID int64, topicNames ...string) error {
topics, err := FindTopics(&FindTopicOptions{
@ -113,7 +118,8 @@ func SaveTopics(repoID int64, topicNames ...string) error {
var addedTopicNames []string
for _, topicName := range topicNames {
if strings.TrimSpace(topicName) == "" {
topicName = validTopic(topicName)
if topicName == "" {
continue
}
@ -133,6 +139,11 @@ func SaveTopics(repoID int64, topicNames ...string) error {
for _, t := range topics {
var found bool
for _, topicName := range topicNames {
topicName = validTopic(topicName)
if topicName == "" {
continue
}
if strings.EqualFold(topicName, t.Name) {
found = true
break

View File

@ -2301,12 +2301,23 @@ function initNavbarContentToggle() {
});
}
function pasteFilter(e) {
e.preventDefault();
var contentOnBlur = (e.originalEvent || e).clipboardData.getData('text/plain');
contentOnBlur = contentOnBlur.replace(/(<([^>]+)>)/ig,'');
document.execCommand('insertText', false, contentOnBlur);
}
function initTopicbar() {
var mgrBtn = $("#manage_topic")
var editDiv = $("#topic_edit")
var viewDiv = $("#repo-topic")
var saveBtn = $("#save_topic")
editDiv.on("paste", function(e){
pasteFilter(e);
});
mgrBtn.click(function() {
viewDiv.hide();
editDiv.show();