Skip to content

Commit 2092f82

Browse files
committed
fixup! fix: escape error.message on login failure
1 parent 22a22a8 commit 2092f82

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/node/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,5 @@ export function escapeHtml(unsafe: string): string {
520520
.replace(/</g, "&lt;")
521521
.replace(/>/g, "&gt;")
522522
.replace(/"/g, "&quot;")
523-
.replace(/'/g, "&#039;")
523+
.replace(/'/g, "&apos;")
524524
}

test/unit/node/util.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ describe("onLine", () => {
448448

449449
describe("escapeHtml", () => {
450450
it("should escape HTML", () => {
451-
expect(util.escapeHtml(`<div class="error">"Hello & world"</div>`)).toBe(
452-
"&lt;div class=&quot;error&quot;&gt;&quot;Hello &amp; world&quot;&lt;/div&gt;",
451+
expect(util.escapeHtml(`<div class="error">"'ello & world"</div>`)).toBe(
452+
"&lt;div class=&quot;error&quot;&gt;&quot;&apos;ello &amp; world&quot;&lt;/div&gt;",
453453
)
454454
})
455455
})

test/unit/routes/login.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,14 @@ describe("login", () => {
6060
process.env.PASSWORD = previousEnvPassword
6161
})
6262

63-
it("should return escaped HTML with 'Missing password' message", async () => {
63+
it("should return HTML with 'Missing password' message", async () => {
6464
const resp = await codeServer().fetch("/login", { method: "POST" })
6565

6666
expect(resp.status).toBe(200)
6767

6868
const htmlContent = await resp.text()
6969

70-
expect(htmlContent).not.toContain(">")
71-
expect(htmlContent).not.toContain("<")
72-
expect(htmlContent).not.toContain('"')
73-
expect(htmlContent).not.toContain("'")
74-
expect(htmlContent).toContain("&lt;div class=&quot;error&quot;&gt;Missing password&lt;/div&gt;")
70+
expect(htmlContent).toContain("Missing password")
7571
})
7672
})
7773
})

0 commit comments

Comments
 (0)