|
1 | 1 | import type { Stats as FSStats } from 'node:fs'; |
2 | 2 | import path from 'node:path'; |
3 | 3 | import { unescape as qsUnescape } from 'node:querystring'; |
4 | | -import { parse } from 'node:url'; |
5 | 4 | import type { EnvironmentContext } from '../../types'; |
6 | 5 | import type { OutputFileSystem } from './index'; |
7 | | -import { memorize } from './memorize'; |
8 | | - |
9 | | -// TODO: type the cache options instead of using any for the second parameter |
10 | | -const memoizedParse = memorize(parse, undefined, (value: any) => { |
11 | | - if (value.pathname) { |
12 | | - value.pathname = decode(value.pathname); |
13 | | - } |
14 | | - |
15 | | - return value; |
16 | | -}); |
17 | 6 |
|
18 | 7 | const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/; |
19 | 8 |
|
20 | | -function decode(input: string): string { |
21 | | - return qsUnescape(input); |
22 | | -} |
23 | | - |
24 | 9 | export function getFileFromUrl( |
25 | 10 | url: string, |
26 | 11 | outputFileSystem: OutputFileSystem, |
27 | 12 | environments: Record<string, EnvironmentContext>, |
28 | 13 | ): { filename: string; fsStats: FSStats } | { errorCode: number } | undefined { |
29 | | - let urlObject: URL; |
| 14 | + let pathname: string | undefined; |
| 15 | + |
30 | 16 | try { |
31 | | - urlObject = memoizedParse(url, false, true) as URL; |
| 17 | + const urlObject = new URL(url, 'http://localhost'); |
| 18 | + if (urlObject.pathname) { |
| 19 | + pathname = qsUnescape(urlObject.pathname); |
| 20 | + } |
32 | 21 | } catch { |
33 | 22 | return; |
34 | 23 | } |
35 | 24 |
|
36 | | - const { pathname } = urlObject; |
37 | 25 | if (!pathname) { |
38 | 26 | return; |
39 | 27 | } |
|
0 commit comments