fix(app): handle Windows paths in frontend file URL encoding (#12601)

This commit is contained in:
Khang Ha (Kelvin)
2026-02-08 02:27:40 +07:00
committed by GitHub
parent 9401029b1d
commit 4efbfcd087
4 changed files with 558 additions and 4 deletions

View File

@@ -81,7 +81,16 @@ export function decodeFilePath(input: string) {
}
export function encodeFilePath(filepath: string): string {
return filepath
// Normalize Windows paths: convert backslashes to forward slashes
let normalized = filepath.replace(/\\/g, "/")
// Handle Windows absolute paths (D:/path -> /D:/path for proper file:// URLs)
if (/^[A-Za-z]:/.test(normalized)) {
normalized = "/" + normalized
}
// Encode each path segment (preserving forward slashes as path separators)
return normalized
.split("/")
.map((segment) => encodeURIComponent(segment))
.join("/")