Fix bug with highlighting in field formatters (#109401)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Roes 2021-08-20 18:08:12 +02:00 committed by GitHub
parent cd7f26dd81
commit 4d115dcaa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -111,4 +111,18 @@ describe('String Format', () => {
'<span class="ffString__emptyValue">(empty)</span>'
);
});
test('does escape value while highlighting', () => {
const string = new StringFormat();
expect(
stripSpan(
string.convert('<img />', 'html', {
field: { name: 'foo' },
hit: {
highlight: { foo: ['@kibana-highlighted-field@<img />@/kibana-highlighted-field@'] },
},
})
)
).toBe('<mark>&lt;img /&gt;</mark>');
});
});

View file

@ -137,7 +137,7 @@ export class StringFormat extends FieldFormat {
}
return hit?.highlight?.[field?.name]
? getHighlightHtml(val, hit.highlight[field.name])
? getHighlightHtml(escape(val), hit.highlight[field.name])
: escape(this.textConvert(val));
};
}