From 55cd4a624882773604f606f24c5cf4847f62d769 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 01:02:56 -0500 Subject: [PATCH 1/6] Don't manually replace whitespace during render For historical reasons Gitea manually alters the urlPrefix and replaces a whitespace with a +. This Works for URLs, but we're also passing urlPrefix to git calls and adding the + is breaking the tree path. Goldmark will automatically convert a white space to the proper %20, so we should leave the string as is which lets us pass it to git unmodified and then let Goldmark fix it. Also fixed separate bug in URLJoin I noticed while testing where it will silently discard sections of a path that have # in them (possibly others). We should just escape it first. Fixes 10156 --- modules/markup/markdown/goldmark.go | 1 - modules/markup/markup.go | 1 - modules/util/url.go | 3 +++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index a1c8e1ded0ec4..a9475b58c5a4d 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -52,7 +52,6 @@ func (g *GiteaASTTransformer) Transform(node *ast.Document, reader text.Reader, lnk := string(link) lnk = giteautil.URLJoin(prefix, lnk) - lnk = strings.Replace(lnk, " ", "+", -1) link = []byte(lnk) } v.Destination = link diff --git a/modules/markup/markup.go b/modules/markup/markup.go index 008b21ab977a3..f8deb2b29b1a2 100644 --- a/modules/markup/markup.go +++ b/modules/markup/markup.go @@ -81,7 +81,6 @@ func RenderWiki(filename string, rawBytes []byte, urlPrefix string, metas map[st } func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte { - urlPrefix = strings.Replace(urlPrefix, " ", "+", -1) result := parser.Render(rawBytes, urlPrefix, metas, isWiki) // TODO: one day the error should be returned. result, err := PostProcess(result, urlPrefix, metas, isWiki) diff --git a/modules/util/url.go b/modules/util/url.go index 263255fcd3d6d..1acd713766c7c 100644 --- a/modules/util/url.go +++ b/modules/util/url.go @@ -25,6 +25,9 @@ func PathEscapeSegments(path string) string { // URLJoin joins url components, like path.Join, but preserving contents func URLJoin(base string, elems ...string) string { + // We do need to escape special chars here or else they can be silently discarded + // in the ResolveReference call below + base = PathEscapeSegments(base) if !strings.HasSuffix(base, "/") { base += "/" } From 8bf49596fee6fac4d9da256cd1e90a0ec0183671 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 01:48:49 -0500 Subject: [PATCH 2/6] Escape elems as well --- modules/util/url.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/util/url.go b/modules/util/url.go index 1acd713766c7c..e01d63bc26a38 100644 --- a/modules/util/url.go +++ b/modules/util/url.go @@ -28,6 +28,10 @@ func URLJoin(base string, elems ...string) string { // We do need to escape special chars here or else they can be silently discarded // in the ResolveReference call below base = PathEscapeSegments(base) + for k, v := range elems { + elems[k] = PathEscapeSegments(v) + } + if !strings.HasSuffix(base, "/") { base += "/" } From 331a129108f2510fa3ed69a88dec8f4b6df50402 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 12:13:51 -0500 Subject: [PATCH 3/6] Revert "Escape elems as well" This reverts commit 8bf49596fee6fac4d9da256cd1e90a0ec0183671. --- modules/util/url.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/util/url.go b/modules/util/url.go index e01d63bc26a38..1acd713766c7c 100644 --- a/modules/util/url.go +++ b/modules/util/url.go @@ -28,10 +28,6 @@ func URLJoin(base string, elems ...string) string { // We do need to escape special chars here or else they can be silently discarded // in the ResolveReference call below base = PathEscapeSegments(base) - for k, v := range elems { - elems[k] = PathEscapeSegments(v) - } - if !strings.HasSuffix(base, "/") { base += "/" } From 47ea1a6f0b3171797f9e1865c63d098deba142c0 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 13:18:02 -0500 Subject: [PATCH 4/6] restart ci From ae1cb8cf0ea475ba31b450fb0e910df335390db5 Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 18:06:29 -0500 Subject: [PATCH 5/6] remove changes to URLJoin --- modules/util/url.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/util/url.go b/modules/util/url.go index 1acd713766c7c..263255fcd3d6d 100644 --- a/modules/util/url.go +++ b/modules/util/url.go @@ -25,9 +25,6 @@ func PathEscapeSegments(path string) string { // URLJoin joins url components, like path.Join, but preserving contents func URLJoin(base string, elems ...string) string { - // We do need to escape special chars here or else they can be silently discarded - // in the ResolveReference call below - base = PathEscapeSegments(base) if !strings.HasSuffix(base, "/") { base += "/" } From 80e8cba9f4df7ca6746df2b89c4e7cad8b5f513f Mon Sep 17 00:00:00 2001 From: "j. mccann" Date: Sun, 16 Feb 2020 19:28:58 -0500 Subject: [PATCH 6/6] restart ci