Skip to content

Commit 01b41f8

Browse files
authored
Merge pull request #4 from Nec0ti/dev
Potential fix for code scanning alert no. 1: DOM text reinterpreted as HTML
2 parents 59d78bb + dfb81af commit 01b41f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

script.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,17 @@ invoiceNameInput.addEventListener('input', () => {
7272
analyzeButton.disabled = selectedFiles.length === 0 || !invoiceNameInput.value.trim();
7373
});
7474

75+
function escapeHtml(unsafe) {
76+
return unsafe
77+
.replace(/&/g, "&")
78+
.replace(/</g, "&lt;")
79+
.replace(/>/g, "&gt;")
80+
.replace(/"/g, "&quot;")
81+
.replace(/'/g, "&#039;");
82+
}
83+
7584
function updateFileList() {
76-
fileList.innerHTML = selectedFiles.map(file => `<p>${file.name}</p>`).join('');
85+
fileList.innerHTML = selectedFiles.map(file => `<p>${escapeHtml(file.name)}</p>`).join('');
7786
}
7887

7988
analyzeButton.addEventListener('click', analyzeInvoices);

0 commit comments

Comments
 (0)