Skip to content

Commit 9f3cb4d

Browse files
committed
fix: replace the deprecated url.parse in assets middleware
1 parent 24cf767 commit 9f3cb4d

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

packages/core/src/server/assets-middleware/getFileFromUrl.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
11
import type { Stats as FSStats } from 'node:fs';
22
import path from 'node:path';
33
import { unescape as qsUnescape } from 'node:querystring';
4-
import { parse } from 'node:url';
54
import type { EnvironmentContext } from '../../types';
65
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-
});
176

187
const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
198

20-
function decode(input: string): string {
21-
return qsUnescape(input);
22-
}
23-
249
export function getFileFromUrl(
2510
url: string,
2611
outputFileSystem: OutputFileSystem,
2712
environments: Record<string, EnvironmentContext>,
2813
): { filename: string; fsStats: FSStats } | { errorCode: number } | undefined {
29-
let urlObject: URL;
14+
let pathname: string | undefined;
15+
3016
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+
}
3221
} catch {
3322
return;
3423
}
3524

36-
const { pathname } = urlObject;
3725
if (!pathname) {
3826
return;
3927
}

0 commit comments

Comments
 (0)