fix(link): file URLs not working with Unicode characters on Windows (closes #8973)

This commit is contained in:
Elian Doran
2026-04-13 21:06:50 +03:00
parent c6ea68c012
commit b899a0b5f8
2 changed files with 17 additions and 3 deletions

View File

@@ -339,11 +339,24 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo
// Enable protocols supported by CKEditor 5 to be clickable.
if (utils.isElectron()) {
const electron = utils.dynamicRequire("electron");
electron.shell.openExternal(hrefLink).catch((e: unknown) => {
const reportLinkError = (e: unknown) => {
const message = e instanceof Error ? e.message : String(e);
logError(`Failed to open link '${hrefLink}': ${message}`);
showError(t("link.failed_to_open", { href: hrefLink, message }));
});
};
if (hrefLink.toLowerCase().startsWith("file:")) {
// shell.openExternal mishandles Unicode file:// URLs on Windows;
// convert to a filesystem path and use shell.openPath instead.
// Normalize file://c:/... (2 slashes — drive read as host) to file:///c:/...
const normalized = hrefLink.replace(/^file:\/\/(?=[a-zA-Z]:)/i, "file:///");
const { fileURLToPath } = utils.dynamicRequire("url");
electron.shell.openPath(fileURLToPath(normalized)).then((err: string) => {
if (err) reportLinkError(new Error(err));
}).catch(reportLinkError);
} else {
electron.shell.openExternal(hrefLink).catch(reportLinkError);
}
} else {
window.open(hrefLink, "_blank");
}

View File

@@ -360,7 +360,8 @@ function copySelectionToClipboard() {
type dynamicRequireMappings = {
"@electron/remote": typeof import("@electron/remote"),
"electron": typeof import("electron"),
"child_process": typeof import("child_process")
"child_process": typeof import("child_process"),
"url": typeof import("url")
};
export function dynamicRequire<T extends keyof dynamicRequireMappings>(moduleName: T): Awaited<dynamicRequireMappings[T]>{