fix: escape html to get tooltip text (#167)
This commit is contained in:
parent
f990c1ff87
commit
6c79a19b29
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/utils.js
16
src/utils.js
@ -149,3 +149,19 @@ export function format(str, args) {
|
|||||||
|
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function escapeHTML(txt) {
|
||||||
|
if (!txt) return '';
|
||||||
|
let escapeHtmlMapping = {
|
||||||
|
'&': '&',
|
||||||
|
'<': '<',
|
||||||
|
'>': '>',
|
||||||
|
'"': '"',
|
||||||
|
"'": ''',
|
||||||
|
'/': '/',
|
||||||
|
'`': '`',
|
||||||
|
'=': '=',
|
||||||
|
};
|
||||||
|
|
||||||
|
return String(txt).replace(/[&<>"'`=/]/g, (char) => escapeHtmlMapping[char] || char);
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user