Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasted images have wrong repo-based URL #15550

Closed
silverwind opened this issue Apr 20, 2021 · 10 comments · Fixed by #15580
Closed

Pasted images have wrong repo-based URL #15550

silverwind opened this issue Apr 20, 2021 · 10 comments · Fixed by #15580
Labels

Comments

@silverwind
Copy link
Member

silverwind commented Apr 20, 2021

Description

Pasting an image results in it being linked on the wrong URL:

https://try.gitea.io/silverwind/symlink-test/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530

But it should be

https://try.gitea.io/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530

Markdown and HTML:

![image](/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530)
<a href="/silverwind/symlink-test/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530" rel="nofollow"><img src="/silverwind/symlink-test/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530" alt="image"></a>

Image attachments via dropzone are not affected, see comment below.

@silverwind
Copy link
Member Author

Possible regression from #15088.

@silverwind
Copy link
Member Author

silverwind commented Apr 20, 2021

I think we need to either generate absolute URLs (like github) or add something else on the produced link that marks it as an server attachment instead of a repo-relative file. Absolute URLs of course won't be portable.

@lunny
Copy link
Member

lunny commented Apr 20, 2021

how about /attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530 means it's an absolute path to the gitea's root url.
attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530 means it's a relative path to the repository or current path.

@silverwind
Copy link
Member Author

silverwind commented Apr 20, 2021

Don't think we can distinguish based on leading characters, GitHub does support all three variants in repo files but notable does not support repo-relative images in issue comments at all.

https://github.com/silverwind/gitea/blob/e71060b08986d747c57cb07cee9dfc53593579a8/test.md

Test code:

![image](./public/img/gitea.svg)

image

![image](/public/img/gitea.svg)

image

![image](public/img/gitea.svg)

image

@silverwind
Copy link
Member Author

silverwind commented Apr 20, 2021

I guess what we could do is check for those /attachments/<id> links and first check if there is an attachments with that id present, otherwise fallback to repo-relative. Probably the only way to keep existing links working. Or just disable repo-relative links in comments like GitHub does, I barely see a use for them.

@lunny
Copy link
Member

lunny commented Apr 20, 2021

Or we can add a new route /:owner/:repo/attachments/<id>

@silverwind
Copy link
Member Author

silverwind commented Apr 20, 2021

I'd be fine with a /:owner/:repo/attachments/<exact-uuidv4> route (e.g. regex route). Chances would be pretty low that someone has such files in a repo.

@lunny
Copy link
Member

lunny commented Apr 20, 2021

Use a uuid rather than id is better.

@yerz
Copy link

yerz commented Apr 22, 2021

image
I upgraded Gitea,Then all the pictures submitted in the issue of my project became like this, and the inaccessible URL was changed

Before the upgrade [Normal preview]
https://my domain/attachments/2622ca24-5a9a-45db-a6ff-aed00717123c

after upgrade [Unable to preview]
https://my domain/organization/project/attachments/2622ca24-5a9a-45db-a6ff-aed00717123c

The pictures of my whole issue can no longer be viewed. 😭

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

this is great, just today I went ahead and hotfixed this on my proxy (nginx string rewrites), now I don't need it anymore.
thanks for the fix y'all! 🚀

@go-gitea go-gitea locked and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants