Skip to content

fix topic special tags #4031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion models/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package models

import (
"fmt"
"html/template"
"strings"

"code.gitea.io/gitea/modules/util"
Expand Down Expand Up @@ -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{
Expand All @@ -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 == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if topicName = validTopic(topicName); len(topicName) == 0 {

continue
}

Expand All @@ -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 == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

continue
}

if strings.EqualFold(topicName, t.Name) {
found = true
break
Expand Down
11 changes: 11 additions & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2301,12 +2301,23 @@ function initNavbarContentToggle() {
});
}

function pasteFilter(e) {
Copy link
Member

@bkcsoft bkcsoft Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this magical function do? Mind adding that to a comment above the function? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It replaces all tags (substrings on the form <...>) with a space, " " when a user pastes, but I agree there should be a comment.

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();
Expand Down