(basePath: string, target: string)
| 58 | * → 'ppt/slides/slide1.xml' |
| 59 | */ |
| 60 | export function resolveRelTarget(basePath: string, target: string): string { |
| 61 | // Absolute targets (start with /) are returned as-is (strip leading /) |
| 62 | if (target.startsWith('/')) { |
| 63 | return target.slice(1) |
| 64 | } |
| 65 | |
| 66 | // Split the base path into segments |
| 67 | const baseParts = basePath.replace(/\\/g, '/').split('/').filter(Boolean) |
| 68 | const targetParts = target.replace(/\\/g, '/').split('/').filter(Boolean) |
| 69 | |
| 70 | // Walk through target parts, resolving '..' by popping base parts |
| 71 | const resolved = [...baseParts] |
| 72 | for (const part of targetParts) { |
| 73 | if (part === '..') { |
| 74 | resolved.pop() |
| 75 | } else if (part !== '.') { |
| 76 | resolved.push(part) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return resolved.join('/') |
| 81 | } |
no test coverage detected