Skip to content

Commit 2312788

Browse files
committed
Ensure we escape sequences of different entities
In a naive, multi-pass entity replacement (eg, replace all `&` with `&amp;`, replace all `<` with `&lt;`) the replacement order is important. (You must replace `&` with `&amp;` first, lest you replace `<` with `&lt;` then replace `&lt;` with `&amp;lt;`.) The `escapeHTML` function is a single-pass replacement of each entity at a time, so is not vulnerable to such a failure mode, but add a test to avoid regressions.
1 parent 696de5a commit 2312788

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/dashboard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe("dashboard", async () => {
1919
status: TestStatus.Fail,
2020
name: "another name escaped 'properly'", // single quotes require escaping
2121
description: "another description escaped & properly", // ampersand requires escaping
22+
},
23+
{
24+
status: TestStatus.Fail,
25+
name: "entities ' are & escaped < in > proper & order",
26+
description: "order is important in a multi-pass replacement",
2227
}
2328
]
2429
}
@@ -29,6 +34,7 @@ describe("dashboard", async () => {
2934
expect(actual).contains("description escaped &quot;properly&quot;")
3035
expect(actual).contains("another name escaped &apos;properly&apos;")
3136
expect(actual).contains("another description escaped &amp; properly")
37+
expect(actual).contains("entities &apos; are &amp; escaped &lt; in &gt; proper &amp; order")
3238
})
3339

3440
it("uses <no name> for test cases without name", async () => {

0 commit comments

Comments
 (0)