[MM-32734] Convert value to string to prevent crash (#5164) (#5171)

* Convert value to string

* Add default value prop

(cherry picked from commit ed4b100962)

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
Mattermost Build 2021-02-10 22:48:15 +01:00 committed by GitHub
parent 79ea18e55e
commit ae7f06bfd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -73,6 +73,7 @@ export default class Markdown extends PureComponent {
disableChannelLink: false,
disableAtChannelMentionHighlight: false,
disableGallery: false,
value: '',
};
constructor(props) {
@ -444,7 +445,7 @@ export default class Markdown extends PureComponent {
};
render() {
let ast = this.parser.parse(this.props.value);
let ast = this.parser.parse(this.props.value.toString());
ast = combineTextNodes(ast);
ast = addListItemIndices(ast);

View file

@ -44,4 +44,15 @@ describe('Markdown', () => {
<Markdown {...props}/>,
);
});
test('should not crash when given a non-string value', () => {
const props = {
...baseProps,
value: 10,
};
shallow(
<Markdown {...props}/>,
);
});
});