Skip to content

Commit 55cd4a6

Browse files
committed
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
1 parent 15614a8 commit 55cd4a6

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

modules/markup/markdown/goldmark.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func (g *GiteaASTTransformer) Transform(node *ast.Document, reader text.Reader,
5252

5353
lnk := string(link)
5454
lnk = giteautil.URLJoin(prefix, lnk)
55-
lnk = strings.Replace(lnk, " ", "+", -1)
5655
link = []byte(lnk)
5756
}
5857
v.Destination = link

modules/markup/markup.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func RenderUncyclo(filename string, rawBytes []byte, urlPrefix string, metas map[st
8181
}
8282

8383
func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isUncyclo bool) []byte {
84-
urlPrefix = strings.Replace(urlPrefix, " ", "+", -1)
8584
result := parser.Render(rawBytes, urlPrefix, metas, isUncyclo)
8685
// TODO: one day the error should be returned.
8786
result, err := PostProcess(result, urlPrefix, metas, isUncyclo)

modules/util/url.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func PathEscapeSegments(path string) string {
2525

2626
// URLJoin joins url components, like path.Join, but preserving contents
2727
func URLJoin(base string, elems ...string) string {
28+
// We do need to escape special chars here or else they can be silently discarded
29+
// in the ResolveReference call below
30+
base = PathEscapeSegments(base)
2831
if !strings.HasSuffix(base, "/") {
2932
base += "/"
3033
}

0 commit comments

Comments
 (0)