From b76550dcd8fb26f5abbbc67ce26f41271f24360d Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 29 May 2024 12:00:07 +0100 Subject: [PATCH] Workaround for rogue HTML entities in dirEntry titles See https://github.com/openzim/mwoffliner/issues/1797 --- www/js/app.js | 6 +++++- www/js/lib/zimDirEntry.js | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index e3303b05..2885e461 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -4860,8 +4860,12 @@ function populateListOfArticles (dirEntryArray, reportingSearch) { // inside double quotes (in the final HTML string), given that dirEntryStringId may contain bare apostrophes // Info: encodeURIComponent encodes all characters except A-Z a-z 0-9 - _ . ! ~ * ' ( ) var dirEntryStringId = encodeURIComponent(dirEntry.toStringId()); + // DEV: Some titles may contain malformed HTML characters like '<i>' for '', so we transform only bold and italics for display + // @TODO: Remove when [openzim/mwoffliner #1797] is fixed + var dirEntryTitle = dirEntry.getTitleOrUrl(); + dirEntryTitle = dirEntryTitle.replace(/<([ib])>([^&]+)<\/\1>/g, '<$1>$2'); articleListDivHtml += '' + (reportingSearch.searchUrlIndex ? dirEntry.namespace + '/' + dirEntry.url : '' + dirEntry.getTitleOrUrl()) + ''; + '" class="list-group-item">' + (reportingSearch.searchUrlIndex ? dirEntry.namespace + '/' + dirEntry.url : '' + dirEntryTitle) + ''; } articleListDiv.innerHTML = articleListDivHtml; // We have to use mousedown below instead of click as otherwise the prefix blur event fires first diff --git a/www/js/lib/zimDirEntry.js b/www/js/lib/zimDirEntry.js index 244d7d92..5f3d7f8a 100644 --- a/www/js/lib/zimDirEntry.js +++ b/www/js/lib/zimDirEntry.js @@ -43,7 +43,6 @@ function DirEntry (zimfile, dirEntryData) { * @returns {String} */ DirEntry.prototype.toStringId = function () { - // @todo also store isRedirect and redirectTarget return this.offset + '|' + this.mimetypeInteger + '|' + this.namespace + '|' + this.cluster + '|' + this.blob + '|' + this.url + '|' + this.title + '|' + this.redirect + '|' + this.redirectTarget; };