(rootDir: string, urlPath: string)
| 223 | * `..%2f` is caught by the same guard as a literal `../`. |
| 224 | */ |
| 225 | export function resolveStaticAsset(rootDir: string, urlPath: string): string | null { |
| 226 | const decoded = decodePath(urlPath); |
| 227 | if (decoded === null) return null; |
| 228 | |
| 229 | const relative = decoded.replace(/^\/+/, ''); |
| 230 | const absolute = validatePathWithinRoot(rootDir, relative); |
| 231 | if (!absolute) return null; |
| 232 | |
| 233 | try { |
| 234 | return fs.statSync(absolute).isFile() ? absolute : null; |
| 235 | } catch { |
| 236 | return null; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Percent-decode a URL path and reject the encodings that only ever show up in |
no test coverage detected