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
This commit is contained in:
Tom Moor
2021-07-28 14:45:47 -04:00
committed by GitHub
parent 2a473bf7b4
commit e53bb8bfbc
2 changed files with 13 additions and 1 deletions

View File

@ -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; return cbUrl && cbResponse && cbResponse.status === 200 ? cbUrl : tileyUrl;
} }

View File

@ -39,3 +39,13 @@ it("should return tiley url if name not provided", async () => {
"https://tiley.herokuapp.com/avatar/bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3/U.png" "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"
);
});