lychee icon indicating copy to clipboard operation
lychee copied to clipboard

Do not assume input to be a URL if the local path doesn't exist

Open mre opened this issue 1 year ago • 1 comments

Context

At the moment, lychee uses the http:// scheme as a fallback for local input paths that don't exist:

> lychee foo
Error: Network error

Caused by:
    0: error sending request for url (http://foo/)
    1: client error (Connect)
    2: dns error: failed to lookup address information: nodename nor servname provided, or not known
    3: failed to lookup address information: nodename nor servname provided, or not known

The idea was to model the behavior after curl, which does the same: https://github.com/curl/curl/blob/70ac27604a2abfa809a7b2736506af0da8c3c8a9/lib/urlapi.c#L1104-L1124

Issue

Getting the scheme guessing correct is quite tricky.

Furthermore, it can be misleading if the user assumes a local path exists, but doesn't. In this case, we make an unexpected network request. This can even go unnoticed in CI/CD in case there happens to be a URL with the same name.

For example, assume we want to check a ZIP archive (which isn't supported, but might be in the future). Furthermore, assume the file doesn't exist. If we run:

lychee --dump-inputs url.zip
http://url.zip/

This would assume http://url.zip/ instead! 💥 (Yes, .zip is a TLD.)

Proposal

I propose to remove the fallback to http. This is a breaking change, which we should make before 1.0.

Necessary changes

Remove the condition here and return an error instead: https://github.com/lycheeverse/lychee/blob/1780aa0daa70462e296f9811e06178f13fd945db/lychee-lib/src/types/input.rs#L180-L187

Add a test to prove correct behavior.

Pull requests greatly appreciated.

mre avatar Dec 18 '24 23:12 mre

Tackling this in #1837. Feedback welcome! Also, if someone could try it, I'd be super thankful.

cargo install --git https://github.com/lycheeverse/lychee/ --branch absolute-local-windows-paths

mre avatar Sep 06 '25 19:09 mre