fix(app): handle Windows paths in frontend file URL encoding (#12601)
This commit is contained in:
committed by
GitHub
parent
9401029b1d
commit
4efbfcd087
@@ -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("/")
|
||||
|
||||
Reference in New Issue
Block a user