-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Does not catch bad links that use absolute paths to repo root #75
Comments
Hey! I don’t think this was supported before. See this handling:
A PR to solve it would likely around that line. And it might need some more testing, to see if Interested in working on this? |
I've got it working with this diff, but you're right there are some edge cases. I don't really care to test on gitlab/bitbucket since I'm not as familiar with them. So how do you feel about this?
If that's ok I'll open a PR. |
I recommend adding an option to Furthermore, you are now creating a path inside For reference, I checked the following in a private repo (
[alpha](/remarkjs/remark-validate-links/readme.md)
[bravo](/remarkjs/remark-validate-links/blob/readme.md)
[charlie](/remarkjs/remark-validate-links/blob/main/readme.md)
[delta](/remarkjs/remark-validate-links)
[echo](/remarkjs)
[foxtrot](/x/y/z.md)
Github generates the following HTML for the readme: <a href="/wooorm/private/blob/main/remarkjs/remark-validate-links/readme.md">alpha</a>
<a href="/wooorm/private/blob/main/remarkjs/remark-validate-links/blob/readme.md">bravo</a>
<a href="/wooorm/private/blob/main/remarkjs/remark-validate-links/blob/main/readme.md">charlie</a>
<a href="/wooorm/private/blob/main/remarkjs/remark-validate-links">delta</a>
<a href="/wooorm/private/blob/main/remarkjs">echo</a>
<a href="/wooorm/private/blob/main/x/y/z.md">foxtrot</a> That is to say, all absolute paths are prefixed with
So, I personally would do something like the following pseudocode: // Absolute paths: `/path/to/file.md`.
if (value.charAt(0) === slash) {
if (!config.urlConfig.hostname) {
return
}
// Create a URL.
const pathname = config.urlConfig.resolveAbsolutePathsInRepo && config.urlConfig.prefix
? config.urlConfig.prefix + 'unknown' + value
: value.slice(1)
value = https + slashes + config.urlConfig.hostname + pathname
} …where Finally, the function as I look at it now is a bit of a mix between path and URL handling. |
Just discovered that this is missing! I thought it was working until I renamed the file that was referenced by relative-to-repo-root syntax. Looking forward to a fix. |
Initial checklist
Affected packages and versions
12.1.0
Link to runnable example
No response
Steps to reproduce
I have a repo: https://github.com/eatonphil/docs-link-check-test. If you run
./remark-check.sh
it will catch one bad link but not another bad link.Expected behavior
GitHub allows you to use absolute paths starting with
/
to mean the root directory of the repo. remark-validate-links should handle looking at the repo root to resolve these files.Actual behavior
Root-absolute paths are not validated.
Runtime
No response
Package manager
No response
OS
No response
Build and bundle tools
No response
The text was updated successfully, but these errors were encountered: