Workaround for rogue HTML entities in dirEntry titles

See https://github.com/openzim/mwoffliner/issues/1797
This commit is contained in:
Jaifroid 2024-05-29 12:00:07 +01:00
parent e422da0e06
commit b76550dcd8
2 changed files with 5 additions and 2 deletions

View File

@ -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 '&lt;i>' for '<i>', so we transform only bold and italics for display
// @TODO: Remove when [openzim/mwoffliner #1797] is fixed
var dirEntryTitle = dirEntry.getTitleOrUrl();
dirEntryTitle = dirEntryTitle.replace(/&lt;([ib])>([^&]+)&lt;\/\1>/g, '<$1>$2</$1>');
articleListDivHtml += '<a href="#" dirEntryId="' + dirEntryStringId +
'" class="list-group-item">' + (reportingSearch.searchUrlIndex ? dirEntry.namespace + '/' + dirEntry.url : '' + dirEntry.getTitleOrUrl()) + '</a>';
'" class="list-group-item">' + (reportingSearch.searchUrlIndex ? dirEntry.namespace + '/' + dirEntry.url : '' + dirEntryTitle) + '</a>';
}
articleListDiv.innerHTML = articleListDivHtml;
// We have to use mousedown below instead of click as otherwise the prefix blur event fires first

View File

@ -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;
};