Skip to content

Using a local --base-url breaks fragments in relative links in local files #1896

@katrinafyi

Description

@katrinafyi
echo '[a](b.html#a)
[a](/b.html#a)
[a](https://a.com/#asd)' > a.md
cargo run --  a.md --base-url $(pwd) --dump
cargo run --  a.md  --dump     

The first command shows this bug. The hash (which should be a fragment) is treated as part of the file name. This only happens on relative links.

file:///home/x/progs/lychee/b.html%23a
https://a.com/#asd
file:///b.html%23a

For comparison, the second command without --base-url leaves the hashes as hashes so they will get picked up as fragments.

    [WARN] Error creating request: InvalidPathToUri("/b.html#a")
https://a.com/#asd
file:///home/x/progs/lychee/b.html#a

I've used --dump for demonstration, but the bug also happens in normal link checking.

$ cargo  run --  a.md --base-url $(pwd)          
[a.md]:
   [ERROR] file:///b.html%23a | Cannot find file: File not found. Check if file exists and path is correct
   [ERROR] file:///home/x/progs/lychee/b.html%23a | Cannot find file: File not found. Check if file exists and path is correct
   [ERROR] https://a.com/#asd | Network error: Connection failed. Check network connectivity and firewall settings

The bug doesn't happen when we use a file:// base because that gets treated as a remote base for the purposes of parsing.

$ cargo run --  a.md --base-url file://$(pwd) --dump 
file:///b.html#a
https://a.com/#asd
file:///home/x/progs/b.html#a

Very fun

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions