( slug: string[], root: string = docsRoot(), )
| 22 | * slug is empty, not a `.md` file, or escapes the root (path-traversal guard). |
| 23 | */ |
| 24 | export function resolveDocPath( |
| 25 | slug: string[], |
| 26 | root: string = docsRoot(), |
| 27 | ): string | null { |
| 28 | if (!slug.length) return null; |
| 29 | const rel = slug.join("/"); |
| 30 | if (!rel.endsWith(".md")) return null; |
| 31 | const abs = resolve(root, rel); |
| 32 | if (abs !== root && !abs.startsWith(root + sep)) return null; |
| 33 | return abs; |
| 34 | } |
| 35 | |
| 36 | /** Read a doc by slug, or null if the slug is invalid or the file is missing. */ |
| 37 | export function readDoc(slug: string[]): string | null { |
no test coverage detected