Skip to content

fix(docs): strip current directory prefix #10955

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ryzhak
Copy link
Contributor

@ryzhak ryzhak commented Jul 8, 2025

Resolves #4533

Right now there's an issue on generating docs which is reproducible in a default forge project:

// works fine
forge doc --out docs 

 // throws "Error: prefix not found"
forge doc --out ./docs

The root cause of the issue is this line. Somehow Path::strip_prefix strips "extra" characters in path, example:

let path_str = "/my/path/./../other1/other2";
let path = Path::new(path_str);
let prefix = "/my/path";
let result = path.strip_prefix(prefix);
println!("<Path> {:?}", result); // <Path> Ok("../other1/other2")

Notice that in the example above the ./ part is also stripped while it was not mentioned in the prefix. Interestingly there is also the String::strip_prefix method which actually works as expected (doesn't strip "extra" characters which can be seen in this rust playground).

What happens here is (roughly) that Path::new("/project/./../project/docs").strip_prefix("/project") returns ../project/docs instead of ./../project/docs which produces the Prefix not found error on subsequent strip_prefix calls.

There're many places where strip_prefix is used (in the forge-doc crate) so I suppose the simplest solution is to remove the ./ prefix from the out option.

Notes:

  • probably there's an easier way to achieve the same result via clap arguments
  • not sure how it affects windows users

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

forge doc --build --root <PATH> --prefix not found error
1 participant