Skip to content

Commit

Permalink
fix: replace a few innerHTML by more secure alternatives (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored Oct 27, 2023
1 parent 3d9aecb commit ada4690
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions controls/slick.columnmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
const spanCloseElm = document.createElement('span');
spanCloseElm.className = 'close';
spanCloseElm.ariaHidden = 'true';
spanCloseElm.innerHTML = '×';
spanCloseElm.textContent = '×';
buttonElm.appendChild(spanCloseElm);
_menuElm.appendChild(buttonElm);

Expand Down Expand Up @@ -300,13 +300,13 @@
col.hidden = false;
visibleColumns.splice(idx, 0, col);
} else {
let newVisibleColumns = [];
let newVisibleColumns = [];
for (let i = 0; i < visibleColumns.length; i++) {
if (visibleColumns[i].id !== col.id) { newVisibleColumns.push(visibleColumns[i]); }
}
visibleColumns = newVisibleColumns;
}

_grid.setColumns(visibleColumns);
onColumnsChanged.notify({ columnId: col.id, showing: show, allColumns: columns, columns: visibleColumns, grid: _grid });
}
Expand Down
6 changes: 3 additions & 3 deletions controls/slick.columnpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
const spanCloseElm = document.createElement('span');
spanCloseElm.className = 'close';
spanCloseElm.ariaHidden = 'true';
spanCloseElm.innerHTML = '&times;';
spanCloseElm.textContent = '×';
buttonElm.appendChild(spanCloseElm);
_menuElm.appendChild(buttonElm);

Expand Down Expand Up @@ -301,13 +301,13 @@
col.hidden = false;
visibleColumns.splice(idx, 0, col);
} else {
let newVisibleColumns = [];
let newVisibleColumns = [];
for (let i = 0; i < visibleColumns.length; i++) {
if (visibleColumns[i].id !== col.id) { newVisibleColumns.push(visibleColumns[i]); }
}
visibleColumns = newVisibleColumns;
}

_grid.setColumns(visibleColumns);
onColumnsChanged.notify({ columnId: col.id, showing: show, allColumns: columns, columns: visibleColumns, grid: _grid });
}
Expand Down
2 changes: 1 addition & 1 deletion controls/slick.gridmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
const spanCloseElm = document.createElement('span');
spanCloseElm.className = 'close';
spanCloseElm.ariaHidden = 'true';
spanCloseElm.innerHTML = '&times;';
spanCloseElm.textContent = '×';
buttonElm.appendChild(spanCloseElm);
_menuElm.appendChild(buttonElm);

Expand Down
2 changes: 1 addition & 1 deletion controls/slick.pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
function destroy() {
setPageSize(0);
_bindingEventService.unbindAll();
container.innerHTML = '';
Slick.Utils.emptyElement(container);
}

function getNavState() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/slick.cellmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
const spanCloseElm = document.createElement('span');
spanCloseElm.className = 'close';
spanCloseElm.ariaHidden = 'true';
spanCloseElm.innerHTML = '&times;';
spanCloseElm.textContent = '×';
closeButtonElm.appendChild(spanCloseElm);

// -- Option List section
Expand Down
2 changes: 1 addition & 1 deletion plugins/slick.contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
const spanCloseElm = document.createElement('span');
spanCloseElm.className = 'close';
spanCloseElm.ariaHidden = 'true';
spanCloseElm.innerHTML = '&times;';
spanCloseElm.textContent = '×';
closeButtonElm.appendChild(spanCloseElm);

// -- Option List section
Expand Down
6 changes: 3 additions & 3 deletions slick.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ if (typeof Slick === "undefined") {
if (len > max) { max = len; maxText = formatterResult; }
}

cellEl.innerHTML = maxText;
cellEl.textContent = maxText;
len = cellEl.offsetWidth;

rowEl.remove();
Expand Down Expand Up @@ -3677,7 +3677,7 @@ if (typeof Slick === "undefined") {
formatterResult = getFormatter(row, m)(row, columnIdx, getDataItemValueForColumn(d, m), m, d, self);
applyFormatResultToCellNode(formatterResult, node);
} else {
node.innerHTML = "";
utils.emptyElement(node);
}
}

Expand Down Expand Up @@ -5280,7 +5280,7 @@ if (typeof Slick === "undefined") {

// don't clear the cell if a custom editor is passed through
if (!editor && !useEditor.suppressClearOnEdit) {
activeCellNode.innerHTML = "";
utils.emptyElement(activeCellNode);
}

var metadata = data.getItemMetadata && data.getItemMetadata(activeRow);
Expand Down

0 comments on commit ada4690

Please sign in to comment.