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

View File

@ -149,3 +149,19 @@ export function format(str, args) {
return str; 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);
};