Skip to content

Commit

Permalink
fix(tooltip): only show tooltip that has value (#1511)
Browse files Browse the repository at this point in the history
- the previous code was having a simple check of the final output text, however when using DOMPurify it returns a TrustedHTML object which is considered defined even though it could be empty.
- we can fix the issue via 2 changes (1. sanitize only string value, 2. check tooltip value against `toString()`
  • Loading branch information
ghiscoding committed May 7, 2024
1 parent a4ef70f commit 2ff15da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/common/src/core/slickGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6296,13 +6296,14 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

/**
* Sanitize possible dirty html string (remove any potential XSS code like scripts and others) when provided as grid option
* @param dirtyHtml: dirty html string
* Sanitize possible dirty html string (remove any potential XSS code like scripts and others) when provided via `sanitizer` grid option.
* The logic will only call the sanitizer if it exists and is a defined string, anything else will be skipped (number, boolean, TrustedHTML will all be skipped)
* @param {*} dirtyHtml: dirty html string
*/
sanitizeHtmlString<T extends string | TrustedHTML>(dirtyHtml: string): T {
if (typeof this._options?.sanitizer === 'function') {
return this._options.sanitizer(dirtyHtml) as T;
sanitizeHtmlString<T extends string | TrustedHTML>(dirtyHtml: unknown): T {
if (typeof this._options?.sanitizer !== 'function' || !dirtyHtml || typeof dirtyHtml !== 'string') {
return dirtyHtml as T;
}
return dirtyHtml as T;
return this._options.sanitizer(dirtyHtml) as T;
}
}
2 changes: 1 addition & 1 deletion packages/custom-tooltip-plugin/src/slickCustomTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class SlickCustomTooltip {
}

// when do have text to show, then append the new tooltip to the html body & reposition the tooltip
if (finalOutputText) {
if (finalOutputText.toString()) {
document.body.appendChild(this._tooltipElm);

// reposition the tooltip on top of the cell that triggered the mouse over event
Expand Down

0 comments on commit 2ff15da

Please sign in to comment.