(rootRealPath: string, requestUrl: string | undefined)
| 57 | }); |
| 58 | |
| 59 | const resolveRequestedFilePath = (rootRealPath: string, requestUrl: string | undefined) => |
| 60 | Effect.gen(function* () { |
| 61 | const path = yield* Path.Path; |
| 62 | const rawPath = (requestUrl ?? "/").split("?", 1)[0] ?? "/"; |
| 63 | const decodedPath = yield* Effect.try({ |
| 64 | try: () => decodeURIComponent(rawPath), |
| 65 | catch: () => null, |
| 66 | }).pipe( |
| 67 | Effect.match({ |
| 68 | onFailure: () => undefined, |
| 69 | onSuccess: (value) => value, |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | if (!decodedPath) { |
| 74 | return undefined; |
| 75 | } |
| 76 | |
| 77 | if (decodedPath.includes("\0")) { |
| 78 | return undefined; |
| 79 | } |
| 80 | |
| 81 | const filePath = path.resolve( |
| 82 | rootRealPath, |
| 83 | `.${decodedPath.startsWith("/") ? decodedPath : `/${decodedPath}`}`, |
| 84 | ); |
| 85 | |
| 86 | return (yield* isOutsideRoot(rootRealPath, filePath)) ? undefined : filePath; |
| 87 | }); |
| 88 | |
| 89 | const isServableFile = (rootRealPath: string, filePath: string) => |
| 90 | Effect.gen(function* () { |
no test coverage detected