1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00

Fix encoding issue

This commit is contained in:
Pierre HUBERT 2019-11-23 19:00:55 +01:00
parent 0cb6688884
commit 17f70b956b
2 changed files with 12 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper"; import { UserHelper } from "../helpers/UserHelper";
import { User, UserPageStatus } from "../entities/User"; import { User, UserPageStatus } from "../entities/User";
import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage"; import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage";
import { fixEncoding } from "../utils/StringUtils";
/** /**
* User information controller * User information controller
@ -50,8 +51,8 @@ export class UserController {
private static UserToAPI(user : User, handler: RequestHandler) : Object { private static UserToAPI(user : User, handler: RequestHandler) : Object {
return { return {
"userID": user.id, "userID": user.id,
"firstName": user.firstName, "firstName": fixEncoding(user.firstName),
"lastName": user.lastName, "lastName": fixEncoding(user.lastName),
"publicPage": user.pageStatus == UserPageStatus.PUBLIC, "publicPage": user.pageStatus == UserPageStatus.PUBLIC,
"openPage": user.pageStatus == UserPageStatus.OPEN, "openPage": user.pageStatus == UserPageStatus.OPEN,
"virtualDirectory": user.virtualDirectory, "virtualDirectory": user.virtualDirectory,

View File

@ -13,3 +13,12 @@
export function checkMail(emailAddress: string): boolean { 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); 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");
}