From b76586c4fda8dd9ea022cd7b18a5051f29cabe1f Mon Sep 17 00:00:00 2001 From: Self Not Found Date: Sun, 12 Mar 2023 23:21:31 +0800 Subject: [PATCH] All: Fixes #7851: Encode the non-ASCII characters in OneDrive URI (#7868) --- packages/lib/SyncTargetOneDrive.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/lib/SyncTargetOneDrive.ts b/packages/lib/SyncTargetOneDrive.ts index fa4e22bbc..295718677 100644 --- a/packages/lib/SyncTargetOneDrive.ts +++ b/packages/lib/SyncTargetOneDrive.ts @@ -103,7 +103,11 @@ export default class SyncTargetOneDrive extends BaseSyncTarget { } this.api_.setAccountProperties(accountProperties); const appDir = await this.api().appDirectory(); - const fileApi = new FileApi(appDir, new FileApiDriverOneDrive(this.api())); + // the appDir might contain non-ASCII characters + // /[^\u0021-\u00ff]/ is used in Node.js to detect the unescaped characters. + // See https://github.com/nodejs/node/blob/bbbf97b6dae63697371082475dc8651a6a220336/lib/_http_client.js#L176 + const baseDir = RegExp(/[^\u0021-\u00ff]/).exec(appDir) !== null ? encodeURI(appDir) : appDir; + const fileApi = new FileApi(baseDir, new FileApiDriverOneDrive(this.api())); fileApi.setSyncTargetId(this.syncTargetId()); fileApi.setLogger(this.logger()); return fileApi;