Relative image paths in readmes are incorrect #4918

Closed
opened 2025-11-02 06:07:15 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @SuperSandro2000 on GitHub (Feb 22, 2020).

  • Gitea version (or commit ref): 1.12.0+dev-354-gc8d1c3812
  • Git version: irrelevant
  • Operating system: Debian
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

When I visit https://try.gitea.io/supersandro2000/hacker-laws I get a 404 for a missing embedded image in the readme. The image is embedded like this <img width="480px" alt="Diagram: Amdahl's Law" src="./images/amdahls_law.png" /> and it resolves that to https://try.gitea.io/supersandro2000/images/amdahls_law.png which is not correct. The repository is a mirror of https://github.com/dwmkerr/hacker-laws.git .

When I open the readme file directly it gets resolved correctly.

Also this triggers a http basic auth on my private instance cause I think some api request has that activated.

Screenshots

Originally created by @SuperSandro2000 on GitHub (Feb 22, 2020). - Gitea version (or commit ref): 1.12.0+dev-354-gc8d1c3812 - Git version: irrelevant - Operating system: Debian - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [x] Yes (provide example URL) - [ ] No - [ ] Not relevant ## Description When I visit https://try.gitea.io/supersandro2000/hacker-laws I get a 404 for a missing embedded image in the readme. The image is embedded like this ``<img width="480px" alt="Diagram: Amdahl's Law" src="./images/amdahls_law.png" />`` and it resolves that to https://try.gitea.io/supersandro2000/images/amdahls_law.png which is not correct. The repository is a mirror of https://github.com/dwmkerr/hacker-laws.git . ~~When I open the [readme file directly](https://try.gitea.io/supersandro2000/hacker-laws/src/branch/master/README.md) it gets resolved correctly.~~ Also this triggers a http basic auth on my private instance cause I think some api request has that activated. ## Screenshots <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the issue/duplicate label 2025-11-02 06:07:15 -06:00
Author
Owner

@silverwind commented on GitHub (Feb 22, 2020):

The issues is that the relative link resolves to https://try.gitea.io/supersandro2000/hacker-laws/src/branch/master/images/amdahls_law.png which is the /src/ page while it should use /raw/ for the actual image resource.

@silverwind commented on GitHub (Feb 22, 2020): The issues is that the relative link resolves to `https://try.gitea.io/supersandro2000/hacker-laws/src/branch/master/images/amdahls_law.png` which is the `/src/` page while it should use `/raw/` for the actual image resource.
Author
Owner

@SuperSandro2000 commented on GitHub (Feb 22, 2020):

You are right. So it does not work either way.

@SuperSandro2000 commented on GitHub (Feb 22, 2020): You are right. So it does not work either way.
Author
Owner

@zeripath commented on GitHub (Feb 22, 2020):

@SuperSandro2000

In fact you should not be using the ./raw endpoint you should use the ./media endpoint as that will transparently work for LFS.

Now if you want to link to an image the simplest thing is to use the ![Diagram: Amdahl's Law](images/amdahls_law.png)

That being said we can do something better with detecting image links. So we should really make these links relative to the media link.

I wonder if the /media link of a markdown file should actually just render the markdown.

@zeripath commented on GitHub (Feb 22, 2020): @SuperSandro2000 In fact you should not be using the `./raw` endpoint you should use the `./media` endpoint as that will transparently work for LFS. Now if you want to link to an image the simplest thing is to use the `![Diagram: Amdahl's Law](images/amdahls_law.png)` That being said we can do something better with detecting image links. So we should really make these links relative to the media link. I wonder if the /media link of a markdown file should actually just render the markdown.
Author
Owner

@SuperSandro2000 commented on GitHub (Feb 22, 2020):

This is not my repo. I just mirrored it from GitHub and I get greeted with a basic auth pop up all the time when I visit it on my private instance and only when I am not logged in on the demo instance. The pop up is the only reason why I reported this as it is very annoying and disrupts the user.

@SuperSandro2000 commented on GitHub (Feb 22, 2020): This is not my repo. I just mirrored it from GitHub and I get greeted with a basic auth pop up all the time when I visit it on my private instance and only when I am not logged in on the demo instance. The pop up is the only reason why I reported this as it is very annoying and disrupts the user.
Author
Owner

@silverwind commented on GitHub (Feb 22, 2020):

In fact you should not be using the ./raw endpoint you should use the ./media endpoint as that will transparently work for LFS.

I'd expect ./image.png links to files in the repo to resolve to the raw endpoint. If the file has a URL in LFS, it could be used instead, but generally the user should not have to care whether LFS is enabled or not so those images work everywhere.

@silverwind commented on GitHub (Feb 22, 2020): > In fact you should not be using the ./raw endpoint you should use the ./media endpoint as that will transparently work for LFS. I'd expect `./image.png` links to files in the repo to resolve to the `raw` endpoint. If the file has a URL in LFS, it could be used instead, but generally the user should not have to care whether LFS is enabled or not so those images work everywhere.
Author
Owner

@6543 commented on GitHub (Feb 24, 2020):

this is a dublicate of #8830

@6543 commented on GitHub (Feb 24, 2020): this is a dublicate of #8830
Author
Owner

@guillep2k commented on GitHub (Feb 25, 2020):

Close in favor of #8830

@guillep2k commented on GitHub (Feb 25, 2020): Close in favor of #8830
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4918