[ResponseOps] escape vertical bars in mustache variables when used with markdown (#136072)

resolves https://github.com/elastic/kibana/issues/135826

Escapes the character `|` in mustache variables used in markdown content,
so that embedded `|` chars in a mustache variable can still be used in 
markdown tables (that use `|`).
This commit is contained in:
Najmieh Sadat 2022-07-13 17:45:42 +04:30 committed by GitHub
parent ed1849688e
commit e0b6517ae5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View file

@ -28,6 +28,7 @@ const variables = {
st: '*',
ul: '_',
st_lt: '*<',
vl: '|',
};
describe('mustache_renderer', () => {
@ -77,6 +78,7 @@ describe('mustache_renderer', () => {
expect(renderMustacheString('{{bs}}', variables, 'markdown')).toBe('\\' + variables.bs);
expect(renderMustacheString('{{st}}', variables, 'markdown')).toBe('\\' + variables.st);
expect(renderMustacheString('{{ul}}', variables, 'markdown')).toBe('\\' + variables.ul);
expect(renderMustacheString('{{vl}}', variables, 'markdown')).toBe('\\' + variables.vl);
});
it('handles triple escapes', () => {

View file

@ -123,6 +123,7 @@ function escapeMarkdown(value: unknown): string {
return `${value}`
.replace(/\\/g, '\\\\')
.replace(/\|/g, '\\|')
.replace(/`/g, '\\`')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_')