Skip to content

Commit

Permalink
Replace innerHTML with innerText
Browse files Browse the repository at this point in the history
For any content where the user can potentially influence the content.
  • Loading branch information
vidartf committed Oct 5, 2021
1 parent 877b842 commit d68aed3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/labextension/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ namespace Private {
<button class="nbdime-export" style="display: none">Export diff</button>
</div>
<div class=nbdime-header-banner>
<span class="nbdime-header-base">${baseLabel}</span>
<span class="nbdime-header-remote">${remoteLabel}</span>
<span class="nbdime-header-base"></span>
<span class="nbdime-header-remote"></span>
</div>`;
(node.getElementsByClassName("nbdime-header-base")[0] as HTMLSpanElement).innerText = baseLabel;
(node.getElementsByClassName("nbdime-header-remote")[0] as HTMLSpanElement).innerText = remoteLabel;

return new Widget({node});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nbdime/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function buildSelect(options: string[], select?: HTMLSelectElement): HTMLSelectE
}
for (let option of options) {
let opt = document.createElement('option');
opt.value = opt.innerHTML = option;
opt.value = opt.innerText = option;
select.appendChild(opt);
}
return select;
Expand Down
7 changes: 5 additions & 2 deletions packages/webapp/src/app/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ function onDiffRequestCompleted(data: any) {
*/
function onDiffRequestFailed(response: string) {
console.log('Diff request failed.');
let root = document.getElementById('nbdime-root');
const root = document.getElementById('nbdime-root');
if (!root) {
throw new Error('Missing root element "nbidme-root"');
}
root.innerHTML = '<pre>' + response + '</pre>';
const pre = document.createElement('pre');
pre.innerText = response;
root.innerHTML = '';
root.appendChild(pre);
diffWidget = null;
toggleSpinner(false);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/webapp/src/app/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ function onMergeRequestFailed(response: string) {
if (!root) {
throw new Error('Missing root element "nbidme-root"');
}
root.innerHTML = '<pre>' + response + '</pre>';
const pre = document.createElement('pre');
pre.innerText = response;
root.innerHTML = '';
root.appendChild(pre);
mergeWidget = null;
toggleSpinner(false);
}
Expand Down

0 comments on commit d68aed3

Please sign in to comment.