-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logger] Strip ANSI escape codes from the message (#164337)
Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
4297b87
commit 4b88b10
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/core/logging/core-logging-common-internal/src/layouts/conversions/message.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { LogLevel, LogRecord } from '@kbn/logging'; | ||
import { MessageConversion } from './message'; | ||
|
||
const baseRecord: LogRecord = { | ||
pid: 1, | ||
timestamp: new Date(), | ||
level: LogLevel.Info, | ||
context: '', | ||
message: '', | ||
}; | ||
|
||
describe('MessageConversion', () => { | ||
test('it should keep break lines', () => { | ||
expect( | ||
MessageConversion.convert({ ...baseRecord, message: 'Hi!\nHow are you?' }, false) | ||
).toEqual('Hi!\nHow are you?'); | ||
}); | ||
|
||
test('it should remove ANSI chars lines from the message', () => { | ||
expect( | ||
MessageConversion.convert( | ||
{ ...baseRecord, message: 'Blinking...\u001b[5;7;6mThis is Fine\u001b[27m' }, | ||
false | ||
) | ||
).toEqual('Blinking...This is Fine'); | ||
}); | ||
|
||
test('it should remove any unicode injection from the message', () => { | ||
expect( | ||
MessageConversion.convert( | ||
{ | ||
...baseRecord, | ||
message: | ||
'\u001b[31mESC-INJECTION-LFUNICODE:\u001b[32mSUCCESSFUL\u001b[0m\u0007\n\nInjecting 10.000 lols 😂\u001b[10000;b\u0007', | ||
}, | ||
false | ||
) | ||
).toEqual('ESC-INJECTION-LFUNICODE:SUCCESSFUL\n\nInjecting 10.000 lols 😂'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters