Skip to content

Commit 3cd709f

Browse files
neuracrcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 707820349
1 parent db19cba commit 3cd709f

File tree

2 files changed

+39
-24495
lines changed

2 files changed

+39
-24495
lines changed

test/builders/html_sanitizer/html_sanitizer_test.ts

+39-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import {secretToken} from '../../../src/internals/secrets';
8-
import {HTML_TEST_VECTORS} from '../../testing/testvectors/html_test_vectors';
98

109
import {
1110
CssSanitizationFn,
@@ -51,16 +50,46 @@ function sanitizeAssertUnchanged(table: SanitizerTable, html: string): string {
5150
.toString();
5251
}
5352

54-
describe('HtmlSanitizer', () => {
55-
describe('using test vectors', () => {
56-
for (const v of HTML_TEST_VECTORS) {
57-
it(`passes testVector[${v.name}]`, () => {
58-
const sanitized = sanitizeHtml(v.input).toString();
59-
expect(v.acceptable).toContain(sanitized);
60-
});
61-
}
62-
});
53+
describe('sanitizeHtml', () => {
54+
interface TestCase {
55+
html: string;
56+
expected: string;
57+
}
58+
const testCases: TestCase[] = [
59+
{
60+
html: '<a href="javascript:evil()"></a>',
61+
expected: '<a href="about:invalid#zClosurez"></a>',
62+
},
63+
{
64+
html: 'ab<script>alert(1)</script>cd',
65+
expected: 'abcd',
66+
},
67+
{
68+
html: 'ab<style>*{}</style>cd',
69+
expected: 'abcd',
70+
},
71+
{
72+
html: '<iframe src="javascript:evil()"></iframe>',
73+
expected: '',
74+
},
75+
{
76+
html: '<img src=1 onerror=alert(1)>',
77+
expected: '<img src="1" />',
78+
},
79+
{
80+
html: '<select><style></select><script>alert(1)</script>',
81+
expected: '<select></select>',
82+
},
83+
];
84+
for (const testCase of testCases) {
85+
it(`sanitizes ${JSON.stringify(testCase.html)} correctly`, () => {
86+
const sanitized = sanitizeHtml(testCase.html).toString();
87+
expect(sanitized).toEqual(testCase.expected);
88+
});
89+
}
90+
});
6391

92+
describe('HtmlSanitizer', () => {
6493
it('drops unknown elements', () => {
6594
const emptyTable = new SanitizerTable(
6695
new Set(),

0 commit comments

Comments
 (0)