From beecaca7db2c210d1dff98b573852541fd9485b7 Mon Sep 17 00:00:00 2001 From: nubenum Date: Sat, 7 Apr 2018 14:30:19 +0200 Subject: [PATCH 1/5] Fix some issues with special chars in branch names * Adding `EscapePound` where necessary for `#?` * Adding `Escape` where `Str2Html` is used to avoid `"` being stripped * Fix last references to legacy URL scheme where possible * Fix legacy redirect Signed-off-by: Robin Durner --- modules/context/repo.go | 4 ++-- templates/repo/activity.tmpl | 2 +- templates/repo/branch/list.tmpl | 4 ++-- templates/repo/commits_table.tmpl | 8 ++++---- templates/repo/editor/commit_form.tmpl | 2 +- templates/repo/editor/edit.tmpl | 4 ++-- templates/repo/home.tmpl | 2 +- templates/repo/issue/view.tmpl | 2 +- templates/repo/pulls/commits.tmpl | 2 +- templates/repo/pulls/files.tmpl | 2 +- templates/repo/release/list.tmpl | 16 ++++++++-------- templates/repo/settings/branches.tmpl | 4 ++-- templates/user/dashboard/feeds.tmpl | 7 ++++--- 13 files changed, 30 insertions(+), 29 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index f3ae33cb50313..53dbaa3bc66fa 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -619,8 +619,8 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { // redirect from old URL scheme to new URL scheme ctx.Redirect(path.Join( setting.AppSubURL, - strings.TrimSuffix(ctx.Req.URL.String(), ctx.Params("*")), - ctx.Repo.BranchNameSubURL(), + path.Dir(ctx.Req.URL.String()), + strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(ctx.Repo.BranchNameSubURL()), ctx.Repo.TreePath)) return } diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl index f5454afb9346a..2adc8e44ce610 100644 --- a/templates/repo/activity.tmpl +++ b/templates/repo/activity.tmpl @@ -84,7 +84,7 @@
{{$.i18n.Tr "repo.activity.published_release_label"}}
{{.TagName}} {{if not .IsTag}} - {{.Title}} + {{.Title}} {{end}} {{TimeSinceUnix .CreatedUnix $.Lang}}

diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index cd6afce9120a1..750526f7a4ee5 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -38,10 +38,10 @@ {{if .IsDeleted}} - {{.Name}} + {{.Name}}

{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n.Lang}}

{{else}} - {{.Name}} + {{.Name}}

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}

{{end}} diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index 8a8e2c369e185..e96abd1b29508 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -5,7 +5,7 @@
{{if .PageIsCommits}} -
+ @@ -83,17 +83,17 @@ {{if gt .TotalPages 1}}
diff --git a/templates/repo/editor/commit_form.tmpl b/templates/repo/editor/commit_form.tmpl index 7b7e2cf4632fa..52d3bc2182a6a 100644 --- a/templates/repo/editor/commit_form.tmpl +++ b/templates/repo/editor/commit_form.tmpl @@ -14,7 +14,7 @@
diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl index 77e40c6de3da0..930c92d605aea 100644 --- a/templates/repo/editor/edit.tmpl +++ b/templates/repo/editor/edit.tmpl @@ -30,8 +30,8 @@
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 9f705c967cfab..b63477509e963 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -27,7 +27,7 @@
diff --git a/templates/repo/pulls/commits.tmpl b/templates/repo/pulls/commits.tmpl index 99bac62cfabfb..d084f9bc5aa04 100644 --- a/templates/repo/pulls/commits.tmpl +++ b/templates/repo/pulls/commits.tmpl @@ -5,7 +5,7 @@
diff --git a/templates/repo/pulls/files.tmpl b/templates/repo/pulls/files.tmpl index 7663788c688ef..8cb006a25d508 100644 --- a/templates/repo/pulls/files.tmpl +++ b/templates/repo/pulls/files.tmpl @@ -5,7 +5,7 @@
diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index af0f0fa82abbb..5f4a00bcb6cfa 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -28,7 +28,7 @@ {{$.i18n.Tr "repo.release.stable"}} {{end}} - {{.TagName}} + {{.TagName}} {{ShortSha .Sha1}} @@ -38,19 +38,19 @@
{{if .IsTag}}

- {{.TagName}} + {{.TagName}}

{{if $.Repository.UnitEnabled $.UnitTypeCode}} {{ShortSha .Sha1}} - ZIP - TAR.GZ + ZIP + TAR.GZ {{end}}
{{else}}

- {{.Title}} - {{if $.IsRepositoryWriter}}({{$.i18n.Tr "repo.release.edit"}}){{end}} + {{.Title}} + {{if $.IsRepositoryWriter}}({{$.i18n.Tr "repo.release.edit"}}){{end}}

@@ -68,10 +68,10 @@

@@ -62,7 +62,7 @@ {{range .ProtectedBranches}}
{{.BranchName}}
- Edit + Edit {{else}} {{.i18n.Tr "repo.settings.no_protected_branch"}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index bdd6c34820d04..bd2ea370e0cec 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -13,8 +13,8 @@ {{else if eq .GetOpType 2}} {{$.i18n.Tr "action.rename_repo" .GetContent .GetRepoLink .ShortRepoPath | Str2html}} {{else if eq .GetOpType 5}} - {{ $branchLink := .GetBranch | EscapePound}} - {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink .GetBranch .ShortRepoPath | Str2html}} + {{ $branchLink := (printf "branch/%s" .GetBranch) | EscapePound | Escape}} + {{$.i18n.Tr "action.commit_repo" .GetRepoLink $branchLink (Escape .GetBranch) .ShortRepoPath | Str2html}} {{else if eq .GetOpType 6}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.create_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} @@ -24,7 +24,8 @@ {{else if eq .GetOpType 8}} {{$.i18n.Tr "action.transfer_repo" .GetContent .GetRepoLink .ShortRepoPath | Str2html}} {{else if eq .GetOpType 9}} - {{$.i18n.Tr "action.push_tag" .GetRepoLink .GetBranch .ShortRepoPath | Str2html}} + {{ $branchLink := .GetBranch | EscapePound | Escape}} + {{$.i18n.Tr "action.push_tag" .GetRepoLink $branchLink .ShortRepoPath | Str2html}} {{else if eq .GetOpType 10}} {{ $index := index .GetIssueInfos 0}} {{$.i18n.Tr "action.comment_issue" .GetRepoLink $index .ShortRepoPath | Str2html}} From d9c1a01c9ba30b16f0268abd11e463a707669340 Mon Sep 17 00:00:00 2001 From: nubenum Date: Mon, 9 Apr 2018 21:10:40 +0200 Subject: [PATCH 2/5] switch to stdlib url escaping Signed-off-by: Robin Durner --- modules/context/repo.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 53dbaa3bc66fa..d39c84ec4747f 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -8,6 +8,7 @@ package context import ( "fmt" "io/ioutil" + "net/url" "path" "strings" @@ -620,7 +621,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { ctx.Redirect(path.Join( setting.AppSubURL, path.Dir(ctx.Req.URL.String()), - strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(ctx.Repo.BranchNameSubURL()), + (&url.URL{Path: ctx.Repo.BranchNameSubURL()}).String(), ctx.Repo.TreePath)) return } From 1237382d65a4ab0d94c0a575d7317e734f47de59 Mon Sep 17 00:00:00 2001 From: nubenum Date: Wed, 13 Jun 2018 22:37:26 +0200 Subject: [PATCH 3/5] Fix legacy redirect for tree, fix code tab escape Signed-off-by: Robin Durner --- modules/context/repo.go | 3 ++- templates/repo/header.tmpl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 8b6eeaf1bcefd..646c9e222b160 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -619,9 +619,10 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { if refType == RepoRefLegacy { // redirect from old URL scheme to new URL scheme + unescaped, _ := url.PathUnescape(ctx.Req.URL.String()) ctx.Redirect(path.Join( setting.AppSubURL, - path.Dir(ctx.Req.URL.String()), + strings.TrimSuffix(unescaped, ctx.Params("*")), (&url.URL{Path: ctx.Repo.BranchNameSubURL()}).String(), ctx.Repo.TreePath)) return diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 6f54cb9f61f7d..981b5f270935b 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -48,7 +48,7 @@