From 17f70b956bedd9aa13cf1954f861777a1fe97004 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Nov 2019 19:00:55 +0100 Subject: [PATCH] Fix encoding issue --- src/controllers/UserController.ts | 5 +++-- src/utils/StringUtils.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 28edb16..8c73102 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -2,6 +2,7 @@ import { RequestHandler } from "../entities/RequestHandler"; import { UserHelper } from "../helpers/UserHelper"; import { User, UserPageStatus } from "../entities/User"; import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage"; +import { fixEncoding } from "../utils/StringUtils"; /** * User information controller @@ -50,8 +51,8 @@ export class UserController { private static UserToAPI(user : User, handler: RequestHandler) : Object { return { "userID": user.id, - "firstName": user.firstName, - "lastName": user.lastName, + "firstName": fixEncoding(user.firstName), + "lastName": fixEncoding(user.lastName), "publicPage": user.pageStatus == UserPageStatus.PUBLIC, "openPage": user.pageStatus == UserPageStatus.OPEN, "virtualDirectory": user.virtualDirectory, diff --git a/src/utils/StringUtils.ts b/src/utils/StringUtils.ts index 7f116c1..2578168 100644 --- a/src/utils/StringUtils.ts +++ b/src/utils/StringUtils.ts @@ -12,4 +12,13 @@ */ export function checkMail(emailAddress: string): boolean { return (emailAddress.match(/^[a-zA-Z0-9_.]+@[a-zA-Z0-9-.]{1,}[.][a-zA-Z]{2,8}$/) === null ? false : true); +} + +/** + * Fix text encoding + * + * @param input Input string + */ +export function fixEncoding(input : string) : string { + return Buffer.from(input, "latin1").toString("utf-8"); } \ No newline at end of file