From e145e083f0f98fb2aa22fbeb4b59d7bbeedab8d7 Mon Sep 17 00:00:00 2001 From: Jade Ferreira Vieira Date: Wed, 19 Aug 2026 15:11:17 -0300 Subject: [PATCH] Fix file URL to path conversion in html-language-features esbuild script (#328557) import.meta.resolve(...).replace('file://', '') is not a correct way to convert a file:// URL to a filesystem path. It always breaks on Windows (leaves a leading slash before the drive letter, e.g. /C:/Users/..., which downstream path.join/fs calls mangle into C:\C:\Users\...), and it also breaks on any OS whenever the resolved path contains a character that gets percent-encoded in a URL, most commonly a space (e.g. file:///home/jane%20doe/... never gets decoded back to "jane doe", so fs.readFileSync fails with ENOENT there too). Use fileURLToPath() from node:url instead, which is Node's own built-in, spec-correct URL-to-path converter and handles both cases. --- extensions/html-language-features/esbuild.browser.mts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/html-language-features/esbuild.browser.mts b/extensions/html-language-features/esbuild.browser.mts index 0e4c1ec91b8..08673a6f8da 100644 --- a/extensions/html-language-features/esbuild.browser.mts +++ b/extensions/html-language-features/esbuild.browser.mts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as fs from 'node:fs'; import * as path from 'node:path'; +import { fileURLToPath } from 'node:url'; import type * as esbuild from 'esbuild'; import { run } from '../esbuild-extension-common.mts'; @@ -19,7 +20,7 @@ function javaScriptLibsPlugin(): esbuild.Plugin { name: 'javascript-libs', setup(build) { build.onLoad({ filter: /javascriptLibs\.ts$/ }, () => { - const TYPESCRIPT_LIB_SOURCE = path.dirname(import.meta.resolve('typescript').replace('file://', '')); + const TYPESCRIPT_LIB_SOURCE = path.dirname(fileURLToPath(import.meta.resolve('typescript'))); const JQUERY_DTS = path.join(extensionRoot, 'server', 'lib', 'jquery.d.ts'); function getFileName(name: string): string {