Archived
1
0

feat: add escapeHtml function

This can be used to escape any special characters in a string with HTML before
sending from the server back to the client. This is important to prevent a
cross-site scripting attack.
This commit is contained in:
Joe Previte
2021-06-29 15:28:44 -07:00
parent faa896c12c
commit c505fc45a8
4 changed files with 67 additions and 2 deletions

View File

@ -445,3 +445,11 @@ describe("onLine", () => {
expect(await received).toEqual(expected)
})
})
describe("escapeHtml", () => {
it("should escape HTML", () => {
expect(util.escapeHtml(`<div class="error">"Hello & world"</div>`)).toBe(
"&lt;div class=&quot;error&quot;&gt;&quot;Hello &amp; world&quot;&lt;/div&gt;",
)
})
})