diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-07-06 12:05:35 -0400 |
---|---|---|
committer | Ethan Koenig <ethantkoenig@gmail.com> | 2017-07-06 12:07:15 -0400 |
commit | b1d7348a20d7d3927d526b15c1847db6dd7767fa (patch) | |
tree | 50e981a977b0019dcc80fe9db41898c11c70fdb2 /modules/markdown/markdown.go | |
parent | a52cd59727f438132a13a33c8941aa05e397331e (diff) | |
download | gitea-b1d7348a20d7d3927d526b15c1847db6dd7767fa.tar.gz gitea-b1d7348a20d7d3927d526b15c1847db6dd7767fa.zip |
Fix wiki preview links
Diffstat (limited to 'modules/markdown/markdown.go')
-rw-r--r-- | modules/markdown/markdown.go | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go index 1f890cc822..d360dfb841 100644 --- a/modules/markdown/markdown.go +++ b/modules/markdown/markdown.go @@ -19,6 +19,7 @@ import ( "golang.org/x/net/html" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" ) @@ -213,36 +214,17 @@ func cutoutVerbosePrefix(prefix string) string { } // URLJoin joins url components, like path.Join, but preserving contents -func URLJoin(elem ...string) string { - res := "" - last := len(elem) - 1 - for i, item := range elem { - res += item - if i != last && !strings.HasSuffix(res, "/") { - res += "/" - } - } - cwdIndex := strings.Index(res, "/./") - for cwdIndex != -1 { - res = strings.Replace(res, "/./", "/", 1) - cwdIndex = strings.Index(res, "/./") - } - upIndex := strings.Index(res, "/..") - for upIndex != -1 { - res = strings.Replace(res, "/..", "", 1) - prevStart := -1 - for i := upIndex - 1; i >= 0; i-- { - if res[i] == '/' { - prevStart = i - break - } - } - if prevStart != -1 { - res = res[:prevStart] + res[upIndex:] - } - upIndex = strings.Index(res, "/..") - } - return res +func URLJoin(base string, elems ...string) string { + u, err := url.Parse(base) + if err != nil { + log.Error(4, "URLJoin: Invalid base URL %s", base) + return "" + } + joinArgs := make([]string, 0, len(elems)+1) + joinArgs = append(joinArgs, u.Path) + joinArgs = append(joinArgs, elems...) + u.Path = path.Join(joinArgs...) + return u.String() } // RenderIssueIndexPattern renders issue indexes to corresponding links. |