mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 19:57:46 -04:00
Port upstream PR that allows use of special characters in search
Former-commit-id: 4c2ba23b7f81e50f64421a3c078c406e9c4fac72 [formerly 558243560bf19d0cfe5951deafce9e8b80c5783b] Former-commit-id: 7c3b7a3f4a942813118f95a80c9506e7de9e5e07
This commit is contained in:
parent
5504884367
commit
7fe7de329c
@ -2256,7 +2256,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
var listLength = dirEntryArray.length < MAX_SEARCH_RESULT_SIZE ? dirEntryArray.length : MAX_SEARCH_RESULT_SIZE;
|
||||
for (var i = 0; i < listLength; i++) {
|
||||
var dirEntry = dirEntryArray[i];
|
||||
articleListDivHtml += '<a href="#" dirEntryId="' + dirEntry.toStringId().replace(/'/g, ''') +
|
||||
var dirEntryStringId = uiUtil.htmlEscapeChars(dirEntry.toStringId());
|
||||
articleListDivHtml += '<a href="#" dirEntryId="' + dirEntryStringId +
|
||||
'" class="list-group-item">' + dirEntry.getTitleOrUrl() + '</a>';
|
||||
}
|
||||
articleListDiv.innerHTML = articleListDivHtml;
|
||||
|
@ -500,6 +500,29 @@ define(['util'], function(util) {
|
||||
return rect.top < window.innerHeight + (offset > 0 ? offset : 0) && rect.bottom > 0 + (offset < 0 ? offset : 0) && rect.left < window.innerWidth && rect.right > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the html escape characters in the string before using it as html class name,id etc.
|
||||
*
|
||||
* @param {String} string The string in which html characters are to be escaped
|
||||
*
|
||||
*/
|
||||
function htmlEscapeChars(string) {
|
||||
var escapechars = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
'/': '/',
|
||||
'`': '`',
|
||||
'=': '='
|
||||
};
|
||||
string = String(string).replace(/[&<>"'`=/]/g, function (s) {
|
||||
return escapechars[s];
|
||||
});
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Functions and classes exposed by this module
|
||||
*/
|
||||
@ -519,6 +542,7 @@ define(['util'], function(util) {
|
||||
displayFileDownloadAlert: displayFileDownloadAlert,
|
||||
insertBreakoutLink: insertBreakoutLink,
|
||||
extractHTML: extractHTML,
|
||||
systemAlert: systemAlert
|
||||
systemAlert: systemAlert,
|
||||
htmlEscapeChars: htmlEscapeChars
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user