gitea change spaces (%20) to signal +

Created on 5 Feb 2020  路  4Comments  路  Source: go-gitea/gitea

Description

Every time I have a directory name with a space and try to use markdown links, gitea change the space to '+' instead of '%20' and it gives 404.
...

Screenshots


Original Markdown
image

Render OK
image

BAD Link (directory with space)
image

kinbug

Most helpful comment

This is because of:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markdown/markdown.go#L33-L38

urlPrefix in this case will be /heliomcp/testes/src/branch/master/Teste+A

Which will be used here to generate the link:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markdown/goldmark.go#L69-L87

Then the link itself fails because it looks for Teste+A here:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/routers/repo/view.go#L503-L508

and fails

2020/02/14 19:07:38 routers/repo/view.go:506:renderCode() [E] Repo.Commit.GetTreeEntryByPath: object does not exist [id: , rel_path: Teste+A]
    /Users/mrsdizzie/.go/src/code.gitea.io/gitea/routers/repo/view.go:506 (0x535b3e8)
        renderCode: ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
    /Users/mrsdizzie/.go/src/code.gitea.io/gitea/routers/repo/view.go:441 (0x535a021)
        Home: renderCode(ctx)

So while a + might be considered valid for the URL it is then being used literally when trying to get the tree entry and fails because there is no path of Teste+A

And source of blank space being converted into a + for ctx.urlPrefix is:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markup.go#L83-L92

So I assume this never worked and isn't related to switching to goldmark. @zeripath -- should we just be be replacing a blank space with %20 when rendering markdown here instead of a +? Just tagging you since you did a lot with the markdown code recently.

I see we do this strings.Replace(var, " ", "+", -1) a couple of places but seems like it should be %20 if those strings are also going to be used for looking at files on disk

All 4 comments

I have included screenshots to exemplify the error.

This is because of:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markdown/markdown.go#L33-L38

urlPrefix in this case will be /heliomcp/testes/src/branch/master/Teste+A

Which will be used here to generate the link:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markdown/goldmark.go#L69-L87

Then the link itself fails because it looks for Teste+A here:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/routers/repo/view.go#L503-L508

and fails

2020/02/14 19:07:38 routers/repo/view.go:506:renderCode() [E] Repo.Commit.GetTreeEntryByPath: object does not exist [id: , rel_path: Teste+A]
    /Users/mrsdizzie/.go/src/code.gitea.io/gitea/routers/repo/view.go:506 (0x535b3e8)
        renderCode: ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
    /Users/mrsdizzie/.go/src/code.gitea.io/gitea/routers/repo/view.go:441 (0x535a021)
        Home: renderCode(ctx)

So while a + might be considered valid for the URL it is then being used literally when trying to get the tree entry and fails because there is no path of Teste+A

And source of blank space being converted into a + for ctx.urlPrefix is:

https://github.com/go-gitea/gitea/blob/a97fe76950bf69ca71c9b790e8d0e76d5e870235/modules/markup/markup.go#L83-L92

So I assume this never worked and isn't related to switching to goldmark. @zeripath -- should we just be be replacing a blank space with %20 when rendering markdown here instead of a +? Just tagging you since you did a lot with the markdown code recently.

I see we do this strings.Replace(var, " ", "+", -1) a couple of places but seems like it should be %20 if those strings are also going to be used for looking at files on disk

That should work.

OK I'll think on it a bit more and do a PR to fix this then

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adpande picture adpande  路  3Comments

jorise7 picture jorise7  路  3Comments

internalfx picture internalfx  路  3Comments

thehowl picture thehowl  路  3Comments

jakimfett picture jakimfett  路  3Comments