Properly decode emoji chars

This commit is contained in:
Silvano Cerza 2025-02-28 17:35:01 +01:00
parent 731920d5a1
commit e4409cb96e
2 changed files with 19 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import MetadataStore, {
import EventsListener from "./events-listener";
import { GitHubSyncSettings } from "./settings/settings";
import Logger from "./logger";
import { decodeBase64String } from "./utils";
interface SyncAction {
type: "upload" | "download" | "delete_local" | "delete_remote";
@ -299,7 +300,9 @@ export default class SyncManager {
}
const blob = await this.client.getBlob(manifest.sha);
const remoteMetadata: Metadata = JSON.parse(atob(blob.content));
const remoteMetadata: Metadata = JSON.parse(
decodeBase64String(blob.content),
);
const conflicts = await this.findConflicts(remoteMetadata.files);
@ -464,7 +467,7 @@ export default class SyncManager {
const res = await this.client.getBlob(
filesMetadata[filePath].sha!,
);
return atob(res.content);
return decodeBase64String(res.content);
})(),
await this.vault.adapter.read(normalizePath(filePath)),
]);

14
src/utils.ts Normal file
View file

@ -0,0 +1,14 @@
import { base64ToArrayBuffer } from "obsidian";
/**
* Decodes a base64 encoded string, this properly
* handles emojis and other non ASCII chars.
*
* @param s base64 encoded string
* @returns Decoded string
*/
export function decodeBase64String(s: string): string {
const buffer = base64ToArrayBuffer(s);
const decoder = new TextDecoder();
return decoder.decode(buffer);
}