Pasted images have wrong repo-based URL #7213

Closed
opened 2025-11-02 07:19:50 -06:00 by GiteaMirror · 10 comments
Owner

Originally created by @silverwind on GitHub (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.

Originally created by @silverwind on GitHub (Apr 20, 2021). - Gitea version (or commit ref): `1.15.0+dev-165-g5e85cdad2` - Can you reproduce the bug at https://try.gitea.io: https://try.gitea.io/silverwind/symlink-test/issues/6#issuecomment-77653 ## 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: ```md ![image](/attachments/265b512e-f7a7-46a0-922c-7afe1bc0f530) ``` ```html <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.
GiteaMirror added the type/bug label 2025-11-02 07:19:50 -06:00
Author
Owner

@silverwind commented on GitHub (Apr 20, 2021):

Possible regression from https://github.com/go-gitea/gitea/pull/15088.

@silverwind commented on GitHub (Apr 20, 2021): Possible regression from https://github.com/go-gitea/gitea/pull/15088.
Author
Owner

@silverwind commented on GitHub (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.

@silverwind commented on GitHub (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.
Author
Owner

@lunny commented on GitHub (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.

@lunny commented on GitHub (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.
Author
Owner

@silverwind commented on GitHub (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.

e71060b089/test.md

Test code:

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

image

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

image

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

image

@silverwind commented on GitHub (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](./public/img/gitea.svg) ``` ![image](/public/img/gitea.svg) ``` ![image](/public/img/gitea.svg) ``` ![image](public/img/gitea.svg) ``` ![image](public/img/gitea.svg)
Author
Owner

@silverwind commented on GitHub (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.

@silverwind commented on GitHub (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.
Author
Owner

@lunny commented on GitHub (Apr 20, 2021):

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

@lunny commented on GitHub (Apr 20, 2021): Or we can add a new route `/:owner/:repo/attachments/<id>`
Author
Owner

@silverwind commented on GitHub (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.

@silverwind commented on GitHub (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.
Author
Owner

@lunny commented on GitHub (Apr 20, 2021):

Use a uuid rather than id is better.

@lunny commented on GitHub (Apr 20, 2021): Use a uuid rather than id is better.
Author
Owner

@yerz commented on GitHub (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. 😭

@yerz commented on GitHub (Apr 22, 2021): ![image](https://user-images.githubusercontent.com/30039842/115646645-2c8e4100-a355-11eb-88a8-d1297f054ae5.png) 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. 😭
Author
Owner

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf commented on GitHub (Apr 23, 2021):

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! 🚀

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf commented on GitHub (Apr 23, 2021): 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! 🚀
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7213