Skip to content

The open source coding agent.

TypeScript

fix(desktop): non-latin file paths failed

Adam184643f0db48
diff --git a/packages/util/src/encode.ts b/packages/util/src/encode.ts
index cc40fbe9d00..fc1f783bf27 100644
--- a/packages/util/src/encode.ts
+++ b/packages/util/src/encode.ts
@@ -1,9 +1,13 @@
export function base64Encode(value: string) {
- return btoa(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
+ const bytes = new TextEncoder().encode(value)
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("")
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
}
export function base64Decode(value: string) {
- return atob(value.replace(/-/g, "+").replace(/_/g, "/"))
+ const binary = atob(value.replace(/-/g, "+").replace(/_/g, "/"))
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0))
+ return new TextDecoder().decode(bytes)
}
export async function hash(content: string, algorithm = "SHA-256"): Promise<string> {