-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- make the level param optional, defaults to info - change the actions logger "tag" from "alerting" to "actions" - remove control characters from message
- Loading branch information
Showing
4 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
x-pack/legacy/plugins/actions/server/builtin_action_types/lib/string_utils.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,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { withoutControlCharacters } from './string_utils'; | ||
|
||
describe('ensureSingleLineString()', () => { | ||
test('works with plain ole strings', () => { | ||
expect(withoutControlCharacters('')).toEqual(''); | ||
expect(withoutControlCharacters(' a b c ')).toEqual(' a b c '); | ||
}); | ||
|
||
test('works with multiple control characters', () => { | ||
expect(withoutControlCharacters(' \r \n ')).toEqual(' ; ; '); | ||
expect(withoutControlCharacters('\r \n ')).toEqual('; ; '); | ||
expect(withoutControlCharacters(' \r \n')).toEqual(' ; ;'); | ||
expect(withoutControlCharacters('\r \n')).toEqual('; ;'); | ||
}); | ||
|
||
test('works with /00-/1F', () => { | ||
for (let c = 0; c <= 0x1f; c++) { | ||
expect(withoutControlCharacters(String.fromCharCode(c))).toEqual(';'); | ||
} | ||
expect(withoutControlCharacters(String.fromCharCode(0x20))).toEqual(' '); | ||
}); | ||
|
||
test('works with /7F-/9F', () => { | ||
expect(withoutControlCharacters(String.fromCharCode(0x7e))).toEqual('~'); | ||
for (let c = 0x7f; c <= 0x9f; c++) { | ||
expect(withoutControlCharacters(String.fromCharCode(c))).toEqual(';'); | ||
} | ||
const nbsp = String.fromCharCode(0xa0); | ||
expect(withoutControlCharacters(nbsp)).toEqual(nbsp); | ||
}); | ||
|
||
test('works with UCS newlines', () => { | ||
expect(withoutControlCharacters('\u2027')).toEqual('\u2027'); | ||
expect(withoutControlCharacters('\u2028')).toEqual(';'); | ||
expect(withoutControlCharacters('\u2029')).toEqual(';'); | ||
expect(withoutControlCharacters('\u202A')).toEqual('\u202A'); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
x-pack/legacy/plugins/actions/server/builtin_action_types/lib/string_utils.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,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// see: https://en.wikipedia.org/wiki/Unicode_control_characters | ||
const CONTROL_CHAR_PATTERN = /[\x00-\x1F]|[\x7F-\x9F]|[\u2028-\u2029]/g; | ||
|
||
// replaces control characters in string with ; | ||
export function withoutControlCharacters(s: string): string { | ||
return s.replace(CONTROL_CHAR_PATTERN, ';'); | ||
} |
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