File: sanitizer-parseHTML.tentative.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (192 lines) | stat: -rw-r--r-- 3,785 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<head>
<title>Testcases for parseHTML and parseHTMLUnsafe</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/html5lib-testcase-support.js"></script>
<!--
  This is a set of basic Sanitizer test cases using the parseHTML and
  parseHTMLUnsafe methods.
-->
<script id="all" type="html5lib-testcases">
#data
text
#document
| <html>
|   <head>
|   <body>
|     "text"

#data
<div>text
#config
{ "elements": ["html", "body", "div"] }
#document
| <html>
|   <body>
|     <div>
|       "text"

#data
<div>text
#config
{ "elements": ["body", "div"] }
#document

#data
<div>text
#config
{ "elements": ["html", "div"] }
#document
| <html>

</script>
<script id="safe" type="html5lib-testcases">
#data
<script>hello
#document
| <html>
|   <head>
|   <body>

#data
<html onload="2+2"><body onload="3+3"><div>hello
#document
| <html>
|   <head>
|   <body>
|     <div>
|       "hello"

#data
<div data-xyz="1" id="2" title="3">
#config
{ "attributes": ["id"] }
#document
| <html>
|   <head>
|   <body>
|     <div>
|       id="2"

#data
<div>a<!-- xx -->b
#config
{ }
#document
| <html>
|   <head>
|   <body>
|     <div>
|       "a"
|       "b"

</script>
<script id="unsafe" type="html5lib-testcases">
#data
<script>hello
#document
| <html>
|   <head>
|     <script>
|       "hello"
|   <body>

#data
<html onload="2+2"><body onload="3+3"><div>hello
#document
| <html>
|   onload="2+2"
|   <head>
|   <body>
|     onload="3+3"
|     <div>
|       "hello"

#data
<div data-xyz="1" id="2" title="3">
#config
{ "attributes": ["id"] }
#document
| <html>
|   <head>
|   <body>
|     <div>
|       data-xyz="1"
|       id="2"

#data
<div>a<!-- xx -->b
#config
{ }
#document
| <html>
|   <head>
|   <body>
|     <div>
|       "a"
|       <!-- xx -->
|       "b"
</script>
<script id="document" type="html5lib-testcases">
#data
<!DOCTYPE html>
text
#document
| <!DOCTYPE html "" "">
| <html>
|   <head>
|   <body>
|     "text"

</script>
<script>
function test_safe(testcase, index) {
  let config = undefined;
  if (testcase.config) {
    config = { sanitizer: JSON.parse(testcase.config) };
  }
  test(_ => {
    assert_testcase(Document.parseHTML(testcase.data, config), testcase);
  }, `parseHTML testcase ${index}, "${testcase.data}"`);
}
function test_unsafe(testcase, index) {
  let config = undefined;
  if (testcase.config) {
    config = { sanitizer: JSON.parse(testcase.config) };
  }
  test(_ => {
    assert_testcase(Document.parseHTMLUnsafe(testcase.data, config), testcase);
  }, `parseHTMLUnsafe testcase ${index}, "${testcase.data}"`);
}

const all = parse_html5lib_testcases(
    document.getElementById("all").textContent);
const safe = parse_html5lib_testcases(
    document.getElementById("safe").textContent);
const unsafe = parse_html5lib_testcases(
    document.getElementById("unsafe").textContent);
all.forEach(test_safe);
all.forEach(test_unsafe);
safe.forEach(test_safe);
unsafe.forEach(test_unsafe);


// DOM only supports Document Type Declarations as children of documents. This
// trips up the assert_testcase implementation, so we'll handle that seperately.
parse_html5lib_testcases(
    document.getElementById("document").textContent).
    forEach((testcase, index) => {
  test(_ => {
    const tree = build_node_tree(new Document(), testcase.document);
    assert_subtree_equals(Document.parseHTMLUnsafe(testcase.data, {}), tree);
  }, `parseHTMLUnsafe full document testcase ${index}, "${testcase.data}"`);
  test(_ => {
    const tree = build_node_tree(new Document(), testcase.document);
    assert_subtree_equals(Document.parseHTML(testcase.data, {}), tree);
  }, `parseHTML full document testcase ${index}, "${testcase.data}"`);
});
</script>
</head>
<body>
</body>