|
1 | 1 | import { describe, it, expect } from "vitest"; |
2 | | -import { getErrorMessage, isObject } from "../../src/ts/utils/misc"; |
| 2 | +import { getErrorMessage, isObject, escapeHTML } from "../../src/ts/utils/misc"; |
3 | 3 | import { |
4 | 4 | getLanguageDisplayString, |
5 | 5 | removeLanguageSize, |
@@ -123,6 +123,46 @@ describe("misc.ts", () => { |
123 | 123 | }); |
124 | 124 | }); |
125 | 125 |
|
| 126 | + describe("escapeHTML", () => { |
| 127 | + it("should escape HTML characters correctly", () => { |
| 128 | + const tests = [ |
| 129 | + { |
| 130 | + input: "hello world", |
| 131 | + expected: "hello world", |
| 132 | + }, |
| 133 | + { |
| 134 | + input: "<script>alert('xss')</script>", |
| 135 | + expected: "<script>alert('xss')</script>", |
| 136 | + }, |
| 137 | + { |
| 138 | + input: 'Hello "world" & friends', |
| 139 | + expected: "Hello "world" & friends", |
| 140 | + }, |
| 141 | + { |
| 142 | + input: "Click `here` to continue", |
| 143 | + expected: "Click `here` to continue", |
| 144 | + }, |
| 145 | + { |
| 146 | + input: null, |
| 147 | + expected: null, |
| 148 | + }, |
| 149 | + { |
| 150 | + input: undefined, |
| 151 | + expected: undefined, |
| 152 | + }, |
| 153 | + { |
| 154 | + input: "", |
| 155 | + expected: "", |
| 156 | + }, |
| 157 | + ]; |
| 158 | + |
| 159 | + tests.forEach((test) => { |
| 160 | + const result = escapeHTML(test.input); |
| 161 | + expect(result).toBe(test.expected); |
| 162 | + }); |
| 163 | + }); |
| 164 | + }); |
| 165 | + |
126 | 166 | describe("getErrorMesssage", () => { |
127 | 167 | it("should correctly get the error message", () => { |
128 | 168 | const tests = [ |
|
0 commit comments