fix(doc): sanitize path separators in generated filenames - #2468
Open
sergioperezcheco wants to merge 1 commit into
Open
fix(doc): sanitize path separators in generated filenames#2468sergioperezcheco wants to merge 1 commit into
sergioperezcheco wants to merge 1 commit into
Conversation
When a command name contains a slash (e.g. Use: "job/first"), the doc generators passed the raw CommandPath to filepath.Join, which interpreted the slash as a directory separator. os.Create then failed with "no such file or directory" because the intermediate directory did not exist. Add a shared filenameForCommand helper that collapses both spaces and forward slashes into the configured separator, and use it in all four generators (md, man, rest, yaml). Add a regression test that generates a tree for a command whose name contains "/". Fixes spf13#1616 Signed-off-by: sergioperezcheco <checo520@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a command name contains a slash (e.g. Use: "job/first"), the doc generators pass the raw CommandPath to filepath.Join, which interprets the slash as a directory boundary. os.Create then fails with "no such file or directory" because the implied parent directory does not exist.
This adds a shared filenameForCommand helper in doc/util.go that collapses both spaces and forward slashes into the configured separator, and wires it into all four tree generators (GenMarkdownTreeCustom, GenManTreeFromOpts, GenReSTTreeCustom, GenYamlTreeCustom). The per-page link generation inside each generator is unchanged since it already replaces spaces, and link references are not passed through filepath.Join.
Includes a regression test generating a markdown tree for a runnable command whose name contains "/", verifying the output file lands at root_job_first.md instead of root_job/first.md.
Fixes #1616