Skip to content

Commit

Permalink
fix(common): Select Filter/Editor regular text shouldn't be html enco…
Browse files Browse the repository at this point in the history
…ded (#1011)

* fix(common): Select Filter/Editor regular text shouldn't be html encoded
- fix a regression bug introduced by PR #976 when migrating from ms-select to ms-select-vanilla, the text should be encode only when `renderHtmlEnabled` is enabled and not encoded when it's the flag is disabled, basically the html encode was set on the wrong condition
  • Loading branch information
ghiscoding committed Jun 28, 2023
1 parent fa81d7a commit c203a2c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/vite-demo-vanilla-bundle/package.json
Expand Up @@ -27,7 +27,7 @@
"fetch-jsonp": "^1.2.3",
"flatpickr": "^4.6.13",
"moment-mini": "^2.29.4",
"multiple-select-vanilla": "^0.4.3",
"multiple-select-vanilla": "^0.4.4",
"rxjs": "^7.8.1",
"whatwg-fetch": "^3.6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Expand Up @@ -78,7 +78,7 @@
"dompurify": "^3.0.3",
"flatpickr": "^4.6.13",
"moment-mini": "^2.29.4",
"multiple-select-vanilla": "^0.4.3",
"multiple-select-vanilla": "^0.4.4",
"slickgrid": "^4.0.0",
"sortablejs": "^1.15.0",
"un-flatten-tree": "^2.0.12"
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/filters/selectFilter.ts
Expand Up @@ -416,6 +416,7 @@ export class SelectFilter implements Filter {
filter: false, // input search term on top of the select option list
maxHeight: 275,
single: true,
useSelectOptionLabelToHtml: this.columnFilter?.enableRenderHtml ?? false,
sanitizer: (dirtyHtml: string) => sanitizeTextByAvailableSanitizer(this.gridOptions, dirtyHtml),
// we will subscribe to the onClose event for triggering our callback
// also add/remove "filled" class for styling purposes
Expand Down
11 changes: 6 additions & 5 deletions packages/common/src/services/domUtilities.ts
Expand Up @@ -89,8 +89,6 @@ export function buildMultipleSelectDataCollection(type: 'editor' | 'filter', col
// sanitize any unauthorized html tags like script and others
// for the remaining allowed tags we'll permit all attributes
optionText = sanitizeTextByAvailableSanitizer(gridOptions, optionText, sanitizedOptions);
} else {
optionText = htmlEncode(optionText);
}
selectOption.text = optionText;

Expand Down Expand Up @@ -297,16 +295,19 @@ export function findWidthOrDefault(inputWidth?: number | string, defaultValue =
* HTML encode using a plain <div>
* Create a in-memory div, set it's inner text(which a div can encode)
* then grab the encoded contents back out. The div never exists on the page.
* @param {String} inputValue - input value to be encoded
* @return {String}
*/
export function htmlEncode(inputValue: string): string {
const entityMap = {
const val = typeof inputValue === 'string' ? inputValue : String(inputValue);
const entityMap: { [char: string]: string; } = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#39;'
'\'': '&#39;',
};
return (inputValue || '').toString().replace(/[&<>"']/g, (s) => (entityMap as any)[s]);
return (val || '').toString().replace(/[&<>"']/g, (s) => entityMap[s as keyof { [char: string]: string; }]);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c203a2c

Please sign in to comment.