From e53bb8bfbc65e20c6bfb56a663c723cf0da55cd1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 28 Jul 2021 14:45:47 -0400 Subject: [PATCH] fix: Error uploading fallback avatar when name contains characters that need to be escaped (#2387) * Todo -> Task to match new langauge elsewhere * fix: Correctly escape characters in Tiley url * Move encoding to avatars logic, add test --- server/utils/avatars.js | 4 +++- server/utils/avatars.test.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server/utils/avatars.js b/server/utils/avatars.js index 14b66d1e..78d70c3b 100644 --- a/server/utils/avatars.js +++ b/server/utils/avatars.js @@ -29,6 +29,8 @@ export async function generateAvatarUrl({ } } - const tileyUrl = `${DEFAULT_AVATAR_HOST}/avatar/${hashedId}/${name[0]}.png`; + const tileyUrl = `${DEFAULT_AVATAR_HOST}/avatar/${hashedId}/${encodeURIComponent( + name[0] + )}.png`; return cbUrl && cbResponse && cbResponse.status === 200 ? cbUrl : tileyUrl; } diff --git a/server/utils/avatars.test.js b/server/utils/avatars.test.js index 937a07e8..f549f6f2 100644 --- a/server/utils/avatars.test.js +++ b/server/utils/avatars.test.js @@ -39,3 +39,13 @@ it("should return tiley url if name not provided", async () => { "https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/U.png" ); }); + +it("should return tiley url with encoded name", async () => { + const url = await generateAvatarUrl({ + id: "google", + name: "цак", + }); + expect(url).toBe( + "https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/%E6%A0%AA.png" + ); +});