forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace control characters before logging (opensearch-project#6402)
Signed-off-by: Miki <miki@amazon.com>
- Loading branch information
Showing
10 changed files
with
174 additions
and
7 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
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,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { cleanControlSequences } from './clean'; | ||
|
||
describe('cleanControlSequences', () => { | ||
it('does its job', () => { | ||
// prettier-ignore | ||
const controlSequences = [ | ||
'\x03', '\x04', '\x05', '\x07', '\x08', | ||
'\x0B', '\x0C', '\x0D', '\x0E', '\x0F', | ||
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', | ||
'\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F', | ||
'\x7F', | ||
'\x90', '\x9B', '\x9C' | ||
]; | ||
const input = | ||
'0' + controlSequences.map((char, idx) => `${char}${(idx + 1).toString(36)}`).join(''); | ||
const expected = | ||
'0(U+0003)1(U+0004)2(U+0005)3(U+0007)4(U+0008)' + | ||
'5(U+000b)6(U+000c)7(U+000d)8(U+000e)9(U+000f)' + | ||
'a(U+0010)b(U+0011)c(U+0012)d(U+0013)e(U+0014)f(U+0015)g(U+0016)h(U+0017)i(U+0018)j(U+0019)' + | ||
'k(U+001a)l(U+001b)m(U+001c)n(U+001d)o(U+001e)p(U+001f)' + | ||
'q(U+007f)' + | ||
'r(U+0090)s(U+009b)t(U+009c)' + | ||
'u'; | ||
expect(cleanControlSequences(input)).toEqual(expected); | ||
}); | ||
}); |
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,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Replaces a bunch of characters that should not be printed: | ||
* 0x03 ETX: End of Text | ||
* 0x04 EOT: End of Transmission | ||
* 0x05 ENQ: Enquiry | ||
* 0x07 BEL: Bell | ||
* 0x08 BS: Backspace | ||
* 0x0B VT: Vertical Tabulation | ||
* 0x0C FF: Form Feed | ||
* 0x0D CR: Carriage Return | ||
* 0x0E SO: Shift Out | ||
* 0x0F SI: Shift In | ||
* 0x10 DLE: Data Link Escape | ||
* 0x11 DC1: Device Control One | ||
* 0x12 DC2: Device Control Two | ||
* 0x13 DC3: Device Control Three | ||
* 0x14 DC4: Device Control Four | ||
* 0x15 NAK: Negative Acknowledge | ||
* 0x16 SYN: Synchronous Idle | ||
* 0x17 ETB: End of Transmission Block | ||
* 0x18 CAN: Cancel | ||
* 0x19 EM: End of Medium | ||
* 0x1A SUB: EoF on Windows | ||
* 0x1B ESC: Starts all the escape sequences | ||
* 0x1C FS: File Separator | ||
* 0x1D GS: Group Separator | ||
* 0x1E RS: Record Separator | ||
* 0x1F US: Unit Separator | ||
* 0x7F Del | ||
* 0x90 DCS: Device Control String | ||
* 0x9B CSI: Control Sequence Introducer | ||
* 0x9C OSC: Operating System Command | ||
* | ||
* Ref: https://en.wikipedia.org/wiki/Control_character | ||
*/ | ||
export const cleanControlSequences = (text: string): string => { | ||
return text.replace( | ||
/[\x03-\x05\x07\x08\x0B-\x1F\x7F\x90\x9B\x9C]/g, | ||
(char) => `(U+${char.charCodeAt(0).toString(16).padStart(4, '0')})` | ||
); | ||
}; |
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
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
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