Commit ff53ca3
authored
feat(base-url)!: disallow relative local base to avoid confusion (#1857)
* feat(base-url)!: disallow relative directory paths in `--base-url`
the previous behaviour accepted relative directory paths as bases
but this led to later InvalidBaseJoin errors, because relative paths
cannot be used to join relative URLs. this means that relative local
bases were *only* useful for resolving root-relative links, and were
confusingly problematic with ordinary relative links.
see https://www.github.com/lycheeverse/lychee/issues/1574 which talks about
errors when passing `--base ../network-documentation/` or, in a later
comment, `--base build`.
also, the previous behaviour would parse something like
`--base-url google.com` to a local base pointing to `./google.com`.
this would also lead to downstream errors and it's better to guard
against this.
it is my opinion that it is better to fail earlier in these cases, so
the user is not hit with mysterious InvalidBaseJoin.
after this pr, there will be a command-line argument parsing error:
```
error: invalid value 'build' for '--base-url <BASE_URL>': Error with
base dir `build` : Base must either be a URL (with scheme) or an
absolute path. Alternatively, if you want to resolve root-relative links
in local files, see `--root-dir`.
```
in a slightly opinionated touch, i've mentioned --root-dir in the error
message, since i think --root-dir is more suitable for most use cases
where people try to use relative local bases. this agrees with later
comments in https://www.github.com/lycheeverse/lychee/issues/1574.
however, this does make the error message quite long. so i'm happy to
take on feedback and changes about this.
this pr implements (1) in my outline to reduce InvalidBaseJoin
confusion, as described in
https://www.github.com/lycheeverse/lychee/pull/1624#issuecomment-3274485963
* clippy
* clipy 2
* review: add --help mention
TODO: probably mention these restrictions and suggestions in --help too
* add sentence to --help
* move CLI-related suggestions into .context in lychee-bin
this does have the side-effect of attaching the --help and --root-dir
suggestions even to the "cannot be a base" error.
```
error: invalid value 'a:datafdajsio' for '--base-url <BASE_URL>': Error
with base dir `a:datafdajsio` : The given URL cannot be used as a base
URL. See `--help` for more information. If you want to resolve
root-relative links in local files, also see `--root-dir`.
```
this could be a bit confusing, but idk a way around it without
inspecting the error message of InvalidBase to determine which context
to add.
* shuffle extra notes about --base-url to the end of its help, and
add a sentence about URL schemes to cover the "cannot be a base"
error.1 parent 73249e0 commit ff53ca3
File tree
4 files changed
+45
-6
lines changed- lychee-bin/src
- lychee-lib/src/types
4 files changed
+45
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
599 | 602 | | |
600 | 603 | | |
601 | 604 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
753 | | - | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
754 | 757 | | |
755 | 758 | | |
756 | 759 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
18 | 30 | | |
19 | 31 | | |
20 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
65 | 77 | | |
66 | 78 | | |
67 | 79 | | |
| |||
96 | 108 | | |
97 | 109 | | |
98 | 110 | | |
99 | | - | |
| 111 | + | |
100 | 112 | | |
101 | 113 | | |
102 | 114 | | |
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
106 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
107 | 128 | | |
108 | 129 | | |
109 | 130 | | |
| |||
0 commit comments