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:
@ -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;
|
||||
}
|
||||
|
@ -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"
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user