fix: escape html to get tooltip text (#167)

This commit is contained in:
Shariq Ansari 2023-01-25 18:37:24 +05:30 committed by GitHub
parent f990c1ff87
commit 6c79a19b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -2,7 +2,8 @@ import {
copyTextToClipboard,
makeDataAttributeString,
throttle,
linkProperties
linkProperties,
escapeHTML,
} from './utils';
import $ from './dom';
import icons from './icons';
@ -886,7 +887,7 @@ export default class CellManager {
let textContent = div.textContent;
textContent = textContent.replace(/\s+/g, ' ').trim();
cellContentHTML = cellContentHTML.replace('>', ` title="${textContent}">`);
cellContentHTML = cellContentHTML.replace('>', ` title="${escapeHTML(textContent)}">`);
return cellContentHTML;
}

View File

@ -149,3 +149,19 @@ export function format(str, args) {
return str;
};
export function escapeHTML(txt) {
if (!txt) return '';
let escapeHtmlMapping = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;',
};
return String(txt).replace(/[&<>"'`=/]/g, (char) => escapeHtmlMapping[char] || char);
};