1
1
mirror of https://github.com/go-gitea/gitea synced 2024-06-03 01:45:47 +00:00

modules/base: add RenderCommitMessage with XSS-safe and special links

- update russian locale
This commit is contained in:
Unknwon 2015-01-30 18:05:20 -05:00
parent 9803f84c88
commit 37fcc8daf2
12 changed files with 27 additions and 21 deletions

View File

@ -7,7 +7,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go.
![Demo](http://gogs.qiniudn.com/gogs_demo.gif) ![Demo](http://gogs.qiniudn.com/gogs_demo.gif)
##### Current version: 0.5.11 Beta ##### Current version: 0.5.12 Beta
### NOTICES ### NOTICES

View File

@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。
![Demo](http://gogs.qiniudn.com/gogs_demo.gif) ![Demo](http://gogs.qiniudn.com/gogs_demo.gif)
##### 当前版本0.5.11 Beta ##### 当前版本0.5.12 Beta
## 开发目的 ## 开发目的

View File

@ -164,7 +164,7 @@ unable_verify_ssh_key=Gogs не может проверить ваш SSH-клю
auth_failed=Ошибка аутентификации: %v auth_failed=Ошибка аутентификации: %v
still_own_repo=На вашем аккаунте все еще остается как минимум один репозиторий, сначала вам нужно удалить или передать его. still_own_repo=На вашем аккаунте все еще остается как минимум один репозиторий, сначала вам нужно удалить или передать его.
still_has_org=Your account still have membership of organization, you have to left or delete them first. still_has_org=Вы находитесь в организации, сперва Вам необходимо покинуть ее или удалить.
org_still_own_repo=Данная организация все еще является владельцем репозиториев, необходимо удалить или переместить их в начале. org_still_own_repo=Данная организация все еще является владельцем репозиториев, необходимо удалить или переместить их в начале.
still_own_user=Эта проверка подлинности по-прежнему используется некоторыми пользователями, вы должны переместить их и затем снова удалить. still_own_user=Эта проверка подлинности по-прежнему используется некоторыми пользователями, вы должны переместить их и затем снова удалить.
@ -631,22 +631,22 @@ config.db_path_helper=(for "sqlite3" only)
config.service_config=Service Configuration config.service_config=Service Configuration
config.register_email_confirm=Require E-mail Confirmation config.register_email_confirm=Require E-mail Confirmation
config.disable_register=Отключить регистрацию config.disable_register=Отключить регистрацию
config.require_sign_in_view=Require Sign In View config.require_sign_in_view=Для просмотра необходима авторизация
config.mail_notify=Mail Notification config.mail_notify=Почтовые уведомления
config.enable_cache_avatar=Enable Cache Avatar config.enable_cache_avatar=Кешировать аватар
config.active_code_lives=Active Code Lives config.active_code_lives=Active Code Lives
config.reset_password_code_lives=Reset Password Code Lives config.reset_password_code_lives=Reset Password Code Lives
config.webhook_config=Настройка автоматического обновления репозиции config.webhook_config=Настройка автоматического обновления репозиции
config.task_interval=Task Interval config.task_interval=Интервал задания
config.deliver_timeout=Deliver Timeout config.deliver_timeout=Задержка доставки
config.mailer_config=Mailer Configuration config.mailer_config=Настройки почты
config.mailer_enabled=Включено config.mailer_enabled=Включено
config.mailer_name=Имя config.mailer_name=Имя
config.mailer_host=Сервер config.mailer_host=Сервер
config.mailer_user=Пользователь config.mailer_user=Пользователь
config.oauth_config=Конфигурация OAuth config.oauth_config=Конфигурация OAuth
config.oauth_enabled=Включено config.oauth_enabled=Включено
config.cache_config=Cache Configuration config.cache_config=Настройки кеша
config.cache_adapter=Cache Adapter config.cache_adapter=Cache Adapter
config.cache_interval=Cache Interval config.cache_interval=Cache Interval
config.cache_conn=Cache Connection config.cache_conn=Cache Connection
@ -674,7 +674,7 @@ monitor.execute_times=Execute Times
monitor.process=Запущенные процессы monitor.process=Запущенные процессы
monitor.desc=Описание monitor.desc=Описание
monitor.start=Start Time monitor.start=Start Time
monitor.execute_time=Execution Time monitor.execute_time=Время выполнения
notices.system_notice_list=Система уведомлений notices.system_notice_list=Система уведомлений
notices.type=Тип notices.type=Тип

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.5.12.0120 Beta" const APP_VER = "0.5.12.0130 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -103,7 +103,7 @@ var (
MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)
issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`)
issueIndexPattern = regexp.MustCompile(`#[0-9]+`) issueIndexPattern = regexp.MustCompile(`( |^)#[0-9]+`)
sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`) sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{40}\b`)
) )

View File

@ -90,6 +90,11 @@ func ToUtf8(content string) string {
return res return res
} }
// RenderCommitMessage renders commit message with XSS-safe and special links.
func RenderCommitMessage(msg, urlPrefix string) template.HTML {
return template.HTML(string(RenderIssueIndexPattern([]byte(template.HTMLEscapeString(msg)), urlPrefix)))
}
var mailDomains = map[string]string{ var mailDomains = map[string]string{
"gmail.com": "gmail.com", "gmail.com": "gmail.com",
} }
@ -163,6 +168,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"EscapePound": func(str string) string { "EscapePound": func(str string) string {
return strings.Replace(str, "#", "%23", -1) return strings.Replace(str, "#", "%23", -1)
}, },
"RenderCommitMessage": RenderCommitMessage,
} }
type Actioner interface { type Actioner interface {

View File

@ -37,7 +37,7 @@ func RenderIssueLinks(oldCommits *list.List, repoLink string) *list.List {
newCommits := list.New() newCommits := list.New()
for e := oldCommits.Front(); e != nil; e = e.Next() { for e := oldCommits.Front(); e != nil; e = e.Next() {
c := e.Value.(*git.Commit) c := e.Value.(*git.Commit)
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), repoLink)) c.CommitMessage = c.CommitMessage
newCommits.PushBack(c) newCommits.PushBack(c)
} }
return newCommits return newCommits
@ -206,7 +206,7 @@ func Diff(ctx *middleware.Context) {
commitId := ctx.Repo.CommitId commitId := ctx.Repo.CommitId
commit := ctx.Repo.Commit commit := ctx.Repo.Commit
commit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(commit.CommitMessage), ctx.Repo.RepoLink)) commit.CommitMessage = commit.CommitMessage
diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName),
commitId, setting.Git.MaxGitDiffLines) commitId, setting.Git.MaxGitDiffLines)
if err != nil { if err != nil {

View File

@ -156,9 +156,9 @@ func Home(ctx *middleware.Context) {
for _, f := range files { for _, f := range files {
switch c := f[1].(type) { switch c := f[1].(type) {
case *git.Commit: case *git.Commit:
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), ctx.Repo.RepoLink)) c.CommitMessage = c.CommitMessage
case *git.SubModuleFile: case *git.SubModuleFile:
c.CommitMessage = string(base.RenderIssueIndexPattern([]byte(c.CommitMessage), ctx.Repo.RepoLink)) c.CommitMessage = c.CommitMessage
} }
} }
ctx.Data["Files"] = files ctx.Data["Files"] = files

View File

@ -1 +1 @@
0.5.12.0120 Beta 0.5.12.0130 Beta

View File

@ -32,7 +32,7 @@
{{end}} {{end}}
</td> </td>
<td class="sha"><a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td> <td class="sha"><a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
<td class="message"><span class="text-truncate">{{Str2html .Summary}}</span></td> <td class="message"><span class="text-truncate">{{RenderCommitMessage .Summary $.RepoLink}}</span></td>
<td class="date">{{TimeSince .Author.When $.Lang}}</td> <td class="date">{{TimeSince .Author.When $.Lang}}</td>
</tr> </tr>
{{end}} {{end}}

View File

@ -17,7 +17,7 @@
<div class="panel panel-info panel-radius diff-head-box"> <div class="panel panel-info panel-radius diff-head-box">
<div class="panel-header"> <div class="panel-header">
<a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{.SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a> <a class="pull-right btn btn-blue btn-header btn-medium btn-radius" rel="nofollow" href="{{.SourcePath}}">{{.i18n.Tr "repo.diff.browse_source"}}</a>
<h4 class="commit-message">{{Str2html .Commit.Message}}</h4> <h4 class="commit-message">{{RenderCommitMessage .Commit.Message $.RepoLink}}</h4>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<span class="pull-right"> <span class="pull-right">

View File

@ -53,7 +53,7 @@
<a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.Id}} ">{{SubStr $commit.Id.String 0 10}} </a> <a rel="nofollow" class="label label-green" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.Id}} ">{{SubStr $commit.Id.String 0 10}} </a>
</td> </td>
<td class="message"> <td class="message">
<span class="text-truncate">{{Str2html $commit.Summary}}</span> <span class="text-truncate">{{RenderCommitMessage $commit.Summary $.RepoLink}}</span>
</td> </td>
<td class="age">{{TimeSince $commit.Committer.When $.Lang}}</td> <td class="age">{{TimeSince $commit.Committer.When $.Lang}}</td>
</tr> </tr>