Merge pull request #687 from kiwix/langCatBoxFill

Add undefined check for humanFriendlyTitle
This commit is contained in:
Kelson 2022-01-23 20:39:48 +01:00 committed by GitHub
commit ceb46f1069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -53,8 +53,12 @@
};
const humanFriendlyTitle = (title) => {
if (typeof title === 'string' && title.length > 0) {
title = title.replace(/_/g, ' ');
return htmlEncode(title[0].toUpperCase() + title.slice(1));
} else {
return '';
}
}
function htmlEncode(str) {
@ -238,7 +242,8 @@
data.querySelectorAll('entry').forEach(entry => {
const title = getInnerHtml(entry, 'title');
const value = getInnerHtml(entry, valueEntryNode);
optionStr += `<option value="${value}">${humanFriendlyTitle(title)}</option>`;
const hfTitle = humanFriendlyTitle(title);
optionStr += (hfTitle != '') ? `<option value="${value}">${hfTitle}</option>` : '';
});
document.querySelector(nodeQuery).innerHTML += optionStr;
});