Merge pull request #689 from kiwix/slightly-better-fix-685

Fix title='_' case too #685
This commit is contained in:
Kelson 2022-01-24 09:05:35 +01:00 committed by GitHub
commit 45e9b76b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -55,11 +55,12 @@
const humanFriendlyTitle = (title) => { const humanFriendlyTitle = (title) => {
if (typeof title === 'string' && title.length > 0) { if (typeof title === 'string' && title.length > 0) {
title = title.replace(/_/g, ' '); title = title.replace(/_/g, ' ');
if (title.length > 0) {
return htmlEncode(title[0].toUpperCase() + title.slice(1)); return htmlEncode(title[0].toUpperCase() + title.slice(1));
} else {
return '';
} }
} }
return '';
}
function htmlEncode(str) { function htmlEncode(str) {
return str.replace(/[\u00A0-\u9999<>\&]/gim, (i) => `&#${i.charCodeAt(0)};`); return str.replace(/[\u00A0-\u9999<>\&]/gim, (i) => `&#${i.charCodeAt(0)};`);