mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-21 02:32:30 +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
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
@ -101,15 +101,30 @@ export class ConsoleLoggerService implements LoggerService {
|
||||||
return context;
|
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(
|
private printMessage(
|
||||||
message: unknown,
|
message: unknown,
|
||||||
color: (message: string) => string,
|
color: (message: string) => string,
|
||||||
context = '',
|
context = '',
|
||||||
isTimeDiffEnabled?: boolean,
|
isTimeDiffEnabled?: boolean,
|
||||||
): void {
|
): void {
|
||||||
const output = isObject(message)
|
let output;
|
||||||
? `${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`
|
if (isObject(message)) {
|
||||||
: color(message as string);
|
output = ConsoleLoggerService.sanitize(
|
||||||
|
`${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
output = ConsoleLoggerService.sanitize(color(message as string));
|
||||||
|
}
|
||||||
|
|
||||||
const localeStringOptions: DateTimeFormatOptions = {
|
const localeStringOptions: DateTimeFormatOptions = {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
|
|
Loading…
Add table
Reference in a new issue