|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | | -import { buildReleaseFromTag, detectArch } from "../routes/index"; |
| 2 | +import { buildReleaseFromTag, detectArch, escapeHtml } from "../routes/index"; |
3 | 3 |
|
4 | 4 | describe("detectArch", () => { |
5 | 5 | it("defaults to x64 when no query param or user-agent", () => { |
@@ -64,6 +64,26 @@ describe("detectArch", () => { |
64 | 64 | }); |
65 | 65 | }); |
66 | 66 |
|
| 67 | +describe("escapeHtml", () => { |
| 68 | + it("escapes HTML special characters", () => { |
| 69 | + expect(escapeHtml('<script>alert("xss")</script>')).toBe( |
| 70 | + "<script>alert("xss")</script>", |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + it("escapes ampersands", () => { |
| 75 | + expect(escapeHtml("a&b")).toBe("a&b"); |
| 76 | + }); |
| 77 | + |
| 78 | + it("escapes a malicious tag used in attribute context", () => { |
| 79 | + const malicious = 'x"><img src=x onerror=alert(1)>'; |
| 80 | + const escaped = escapeHtml(malicious); |
| 81 | + expect(escaped).not.toContain("<"); |
| 82 | + expect(escaped).not.toContain(">"); |
| 83 | + expect(escaped).not.toContain('"'); |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
67 | 87 | describe("buildReleaseFromTag", () => { |
68 | 88 | it("constructs download URLs from a tag", () => { |
69 | 89 | const result = buildReleaseFromTag("v0.1.17-alpha.0"); |
|
0 commit comments