ranfdev / Geopard

Colorful, adaptive gemini browser
https://ranfdev.com/projects/Geopard/
GNU General Public License v3.0
144 stars 9 forks source link

Relative links dont work #114

Open trufae opened 3 weeks ago

trufae commented 3 weeks ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to gemini://lolcathost.org/
  2. Click on recipes
  3. Scroll down and click on BROKEN LINK
  4. See error

Expected behavior

Works fine if i do /recipes/fregides.gmi . this link works well in lagrange

Screenshots If applicable, add screenshots to help explain your problem.

Software info (please complete the following information):

Additional context Add any other context about the problem here.

tfuxu commented 3 weeks ago

I can reproduce this on the latest commit. Might be related to https://github.com/ranfdev/Geopard/commit/b27023ff734dbe74cf2e0ff78eb7a7d0ad052001

tfuxu commented 3 weeks ago

Looks like the culprit here is parse_link from Hypertext. The issue stems from base_url() function of url::ParseOptions that cuts path elements from provided URL, if it doesn't have a trailing slash. This is a intended behavior, as noted in join() function (here).

@ranfdev How we should fix it? Lagrange for example just adds a trailing slash at the end of every URL. We could do that, or add a check in parse_link to know when to add slash.

ranfdev commented 2 weeks ago

I've tested the behavior of a simple http server running with python -m http.server, in a folder containing the files

├── subdir
│   ├── index.html
│   └── test.html

Once I try going to localhost/subdir, the python server redirects me to localhost/sudir/, adding a slash. The slash should be added by the server. Only the server knows if localhost/subdir is a file or a folder.

Even the official gemini documentation does this. You can do, from your terminal

echo "gemini://geminiprotocol.net" | gnutls-cli --tofu -p 1965 geminiprotocol.net

and you'll see a redirect

31 gemini://geminiprotocol.net/

Now, for some reason Geopard doesn't update the URL after the redirect. So the slash doesn't seem to be added. That's a problem we can work on.