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

Weird/incorrect behaviour when checking local links #1503

Open
fenuks opened this issue Sep 21, 2024 · 3 comments
Open

Weird/incorrect behaviour when checking local links #1503

fenuks opened this issue Sep 21, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@fenuks
Copy link

fenuks commented Sep 21, 2024

I'm using lychee 0.15.1 on Arch Linux.

Here is an example markdown document:

# Incorrect or strange behaviour
## Links not being checked
- [ ] [Test1](~/Downloads/not checked because of space)
- [ ] [Test3](/home/nonsense/not-checked2-absolute-path)

## Links checking not working because of tilde
- [Test4](~/incorrect-check)
<!-- ✗ [ERR] file:///home/me/Documents/~/incorrect-check | Failed: Cannot find file -->

# Links checked correctly
- [Test5](./correct-check)
<!-- ✗ [ERR] file:///home/me/Documents/correct-check | Failed: Cannot find file -->
$ lychee test.md 
  2/2 ━━━━━━━━━━━━━━━━━━━━ Finished extracting links                                                             Issues found in 1 input. Find details below.

[test.md]:
✗ [ERR] file:///home/fenuks/Dokumenty/notatki/correct-check | Failed: Cannot find file
✗ [ERR] file:///home/fenuks/Dokumenty/notatki/~/incorrect-check | Failed: Cannot find file

🔍 2 Total (in 0s) ✅ 0 OK 🚫 2 Errors

It seems that lychee skips links with absolute path or spaces, and it doesn't handle links with ~ as absolute links.

@mre mre added the bug Something isn't working label Sep 21, 2024
@mre
Copy link
Member

mre commented Jan 6, 2025

Hey, apologies for the late response and thanks for creating the issue.

We don't expand ~ at the moment. I think that's architecture-specific? E.g. if you ran the website on a Windows server, would it handle that case correctly?

As for the absolute path /home/nonsense/not-checked2-absolute-path, I'm guessing you were expecting that lychee expects that file to exist in your filesystem root (i.e. in your /home folder).
However, lychee cannot know what the root directory of your server is. You might run your side from a subdirectory (e.g. https://example.com/blog).

In 0.18.0, you can tell lychee what the root directory is with

lychee --root-dir / test.md

What's left to do is

  • Expand ~ to $HOME (only on Unix).
  • Fix links with spaces.

@mre mre added good first issue Good for newcomers help wanted Extra attention is needed labels Jan 6, 2025
@fenuks
Copy link
Author

fenuks commented Jan 7, 2025

Hello, none apologies needed about response time. ;)

We don't expand ~ at the moment. I think that's architecture-specific? E.g. if you ran the website on a Windows server, would it handle that case correctly?

As far I know, yes, but I don't use Windows.

In 0.18.0, you can tell lychee what the root directory is with

lychee --root-dir / test.md

Thank you! I didn't consider HTTP server root dir use case. Myself, I mostly want to check links in my notes that are consumed directly off-disk, so no HTTP server is involved.

@mre
Copy link
Member

mre commented Jan 9, 2025

I did some research and can't find any reference which says that ~ gets expanded to the home directory on Windows servers (including IIS). So before we make that change, let's find a resource first. Otherwise, we'd end up implementing non-existent functionality and generate false-positives. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants