Skip to content

Commit 3f188cd

Browse files
committed
fixup! fix: escape error.message on login failure
1 parent beaf3ce commit 3f188cd

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/node/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,5 +521,5 @@ export function escapeHtml(unsafe: string): string {
521521
.replace(/</g, "&lt;")
522522
.replace(/>/g, "&gt;")
523523
.replace(/"/g, "&quot;")
524-
.replace(/'/g, "&#039;")
524+
.replace(/'/g, "&apos;")
525525
}

test/unit/node/util.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ describe("onLine", () => {
437437

438438
describe("escapeHtml", () => {
439439
it("should escape HTML", () => {
440-
expect(util.escapeHtml(`<div class="error">"Hello & world"</div>`)).toBe(
441-
"&lt;div class=&quot;error&quot;&gt;&quot;Hello &amp; world&quot;&lt;/div&gt;",
440+
expect(util.escapeHtml(`<div class="error">"'ello & world"</div>`)).toBe(
441+
"&lt;div class=&quot;error&quot;&gt;&quot;&apos;ello &amp; world&quot;&lt;/div&gt;",
442442
)
443443
})
444444
})

test/unit/routes/login.test.ts

Lines changed: 2 additions & 6 deletions
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)