-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
fix topic special tags #4031
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2301,12 +2301,23 @@ function initNavbarContentToggle() { | |
}); | ||
} | ||
|
||
function pasteFilter(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.