Skip to content

Commit 2474cd9

Browse files
committed
update to prevent HTML injection issues
1 parent dc383b1 commit 2474cd9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎debugging/book-library/script.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ function Book(title, author, pages, check) {
6565
this.pages = Number(pages);
6666
this.check = check;
6767
}
68+
69+
function escapeSpecialCharacters(str) {
70+
return str
71+
.replace(/&/g, "&")
72+
.replace(/</g, "&lt;")
73+
.replace(/>/g, "&gt;")
74+
.replace(/"/g, "&quot;")
75+
.replace(/'/g, "&#039;");
76+
}
6877
function alertDeleteToast(message) {
6978
const toast = document.getElementById("toast");
7079
toast.innerHTML = message;
@@ -118,7 +127,7 @@ function render() {
118127
myLibrary.splice(i, 1);
119128
render();
120129
alertDeleteToast(
121-
`You've deleted title: <br> <strong>${deleteTitle}</strong>`
130+
`You've deleted title: <br> <strong>${escapeSpecialCharacters(deleteTitle)}</strong>`
122131
);
123132
});
124133
}

0 commit comments

Comments
 (0)