From 65eea82c3e8b0cc66bf361db6794f7c56859f68b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 13 Mar 2017 16:23:00 +0800 Subject: [PATCH] fix repo settings external tracker failed and check external urls (#1215) (#1236) --- options/locale/locale_en-US.ini | 2 ++ routers/repo/setting.go | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 81e2e9fbc..93151a259 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -718,11 +718,13 @@ settings.wiki_desc = Enable wiki system settings.use_internal_wiki = Use builtin wiki settings.use_external_wiki = Use external wiki settings.external_wiki_url = External Wiki URL +settings.external_wiki_url_error = External Wiki URL is invalid settings.external_wiki_url_desc = Visitors will be redirected to the specified URL when they click on the tab. settings.issues_desc = Enable issue tracker settings.use_internal_issue_tracker = Use builtin issue tracker settings.use_external_issue_tracker = Use external issue tracker settings.external_tracker_url = External Issue Tracker URL +settings.external_tracker_url_error = External Issue Tracker URL is invalid settings.external_tracker_url_desc = Visitors will be redirected to the specified URL when they click on the tab. settings.tracker_url_format = External Issue Tracker URL Format settings.tracker_issue_style = External Issue Tracker Naming Style: diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 91068d242..fb6d68ad9 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -72,6 +72,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { err := models.NewRepoRedirect(ctx.Repo.Owner.ID, repo.ID, repo.Name, newRepoName) if err != nil { ctx.Handle(500, "NewRepoRedirect", err) + return } log.Trace("Repository name changed: %s/%s -> %s", ctx.Repo.Owner.Name, repo.Name, newRepoName) @@ -151,6 +152,12 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { if form.EnableWiki { if form.EnableExternalWiki { + if !strings.HasPrefix(form.ExternalWikiURL, "http://") && !strings.HasPrefix(form.ExternalWikiURL, "https://") { + ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) + ctx.Redirect(repo.Link() + "/settings") + return + } + units = append(units, models.RepoUnit{ RepoID: repo.ID, Type: models.UnitTypeExternalWiki, @@ -171,10 +178,15 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { if form.EnableIssues { if form.EnableExternalTracker { + if !strings.HasPrefix(form.ExternalTrackerURL, "http://") && !strings.HasPrefix(form.ExternalTrackerURL, "https://") { + ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error")) + ctx.Redirect(repo.Link() + "/settings") + return + } units = append(units, models.RepoUnit{ RepoID: repo.ID, - Type: models.UnitTypeExternalWiki, - Index: int(models.UnitTypeExternalWiki), + Type: models.UnitTypeExternalTracker, + Index: int(models.UnitTypeExternalTracker), Config: &models.ExternalTrackerConfig{ ExternalTrackerURL: form.ExternalTrackerURL, ExternalTrackerFormat: form.TrackerURLFormat,