Fix a bug when document.metadata.text is undefined