Skip to content

fix(doc): sanitize path separators in generated filenames - #2468

Open
sergioperezcheco wants to merge 1 commit into
spf13:mainfrom
sergioperezcheco:fix/doc-gen-path-separators
Open

fix(doc): sanitize path separators in generated filenames#2468
sergioperezcheco wants to merge 1 commit into
spf13:mainfrom
sergioperezcheco:fix/doc-gen-path-separators

Conversation

@sergioperezcheco

Copy link
Copy Markdown

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

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>
@CLAassistant

CLAassistant commented Jul 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the area/docs-generation Generation of docs via Cobra label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs-generation Generation of docs via Cobra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: cobra doc generator fails when command contains path separators

2 participants