Skip to content

Commit

Permalink
Merge pull request #2364 from tugcekucukoglu/tooltip
Browse files Browse the repository at this point in the history
Fixed #2363 - Tooltip | Escape encode enhancement
  • Loading branch information
tugcekucukoglu authored Mar 28, 2022
2 parents 0124a70 + a3226ba commit 6f48ac5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UniqueComponentId,DomHandler,ConnectedOverlayScrollHandler,ZIndexUtils} from 'primevue/utils';
import {UniqueComponentId,DomHandler,ConnectedOverlayScrollHandler,ZIndexUtils,ObjectUtils} from 'primevue/utils';

function bindEvents(el) {
const modifiers = el.$_ptooltipModifiers;
Expand Down Expand Up @@ -105,7 +105,9 @@ function create(el) {

let tooltipText = document.createElement('div');
tooltipText.className = 'p-tooltip-text';
tooltipText.innerHTML = el.$_ptooltipValue;

let tooltipLabel = ObjectUtils.htmlEncode(el.$_ptooltipValue);
tooltipText.innerHTML = tooltipLabel;

container.appendChild(tooltipText);
document.body.appendChild(container);
Expand Down
10 changes: 10 additions & 0 deletions src/components/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ export default {
return null;
},

htmlEncode(str){
if (str) {
return str.replace(/[^\w. ]/gi, function(c){
return '&#'+c.charCodeAt(0)+';';
});
}

return null;
},

isEmpty(value) {
return (
value === null || value === undefined || value === '' ||
Expand Down

0 comments on commit 6f48ac5

Please sign in to comment.