( assetsDir: string, pathname: string, )
| 61 | } |
| 62 | |
| 63 | async function resolveStaticFile( |
| 64 | assetsDir: string, |
| 65 | pathname: string, |
| 66 | ): Promise<string | undefined> { |
| 67 | let decoded: string; |
| 68 | try { |
| 69 | decoded = decodeURIComponent(pathname); |
| 70 | } catch { |
| 71 | return undefined; |
| 72 | } |
| 73 | |
| 74 | const normalized = normalize(decoded).replace(/^(\.\.(?:[/\\]|$))+/, ''); |
| 75 | const relative = normalized === sep ? 'index.html' : normalized.replace(/^[/\\]/, ''); |
| 76 | const root = resolve(assetsDir); |
| 77 | const candidate = resolve( |
| 78 | root, |
| 79 | relative.endsWith(sep) ? join(relative, 'index.html') : relative, |
| 80 | ); |
| 81 | if (candidate !== root && !candidate.startsWith(`${root}${sep}`)) { |
| 82 | return undefined; |
| 83 | } |
| 84 | |
| 85 | const info = await stat(candidate).catch(() => undefined); |
| 86 | if (info?.isFile() === true) { |
| 87 | return candidate; |
| 88 | } |
| 89 | if (extname(pathname) !== '') { |
| 90 | return undefined; |
| 91 | } |
| 92 | return join(root, 'index.html'); |
| 93 | } |
| 94 | |
| 95 | function isReservedPath(pathname: string): boolean { |
| 96 | return ( |
no test coverage detected