mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-01 15:01:18 +00:00
feat: add sanitization to logger service
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
f1f1d8cc94
commit
2467b1250f
1 changed files with 19 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
@ -101,15 +101,30 @@ export class ConsoleLoggerService implements LoggerService {
|
|||
return context;
|
||||
}
|
||||
|
||||
static sanitize(input: string): string {
|
||||
return (
|
||||
input
|
||||
// remove ASCII control characters
|
||||
.replace(/\p{C}/gu, '')
|
||||
// replace all non-zeros width spaces with one space
|
||||
.replace(/\p{Zs}/gu, ' ')
|
||||
);
|
||||
}
|
||||
|
||||
private printMessage(
|
||||
message: unknown,
|
||||
color: (message: string) => string,
|
||||
context = '',
|
||||
isTimeDiffEnabled?: boolean,
|
||||
): void {
|
||||
const output = isObject(message)
|
||||
? `${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`
|
||||
: color(message as string);
|
||||
let output;
|
||||
if (isObject(message)) {
|
||||
output = ConsoleLoggerService.sanitize(
|
||||
`${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`,
|
||||
);
|
||||
} else {
|
||||
output = ConsoleLoggerService.sanitize(color(message as string));
|
||||
}
|
||||
|
||||
const localeStringOptions: DateTimeFormatOptions = {
|
||||
year: 'numeric',
|
||||
|
|
Loading…
Reference in a new issue