Skip to content

Commit

Permalink
fix: escape html to get tooltip text (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Jan 25, 2023
1 parent f990c1f commit 6c79a19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cellmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
copyTextToClipboard,
makeDataAttributeString,
throttle,
linkProperties
linkProperties,
escapeHTML,
} from './utils';
import $ from './dom';
import icons from './icons';
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 6c79a19

Please sign in to comment.