File: DOMParser-parseFromString-xml-parsererror.html

package info (click to toggle)
thunderbird 1%3A115.16.0esr-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,476,252 kB
  • sloc: cpp: 6,972,150; javascript: 5,209,211; ansic: 3,507,222; python: 1,137,609; asm: 432,531; xml: 205,149; java: 175,761; sh: 116,485; makefile: 22,152; perl: 13,971; objc: 12,561; yacc: 4,583; pascal: 2,840; lex: 1,720; ruby: 1,075; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (50 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (26)
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
<!DOCTYPE html>
<title>DOMParser: &lt;parsererror> element added on error</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const xhtml_prologue = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' +
                       ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' +
                       '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' +
                       '<body>\n',
      xhtml_epilogue = '</body>\n</html>\n';

[
  '<span x:test="testing">1</span>',                // undeclared 'x' namespace prefix
  '< span>2</span>',                                // bad start tag
  '<span :test="testing">3</span>',                 // empty namespace prefix
  '<span><em>4</span></em>',                        // staggered tags
  '<span>5',                                        // missing end </span> tag
  '6</span>',                                       // missing start <span> tag
  '<span>7< /span>',                                // bad end tag
  '<span>8</ span>',                                // bad end tag
  '<span novalue>9</span>',                         // missing attribute value
  '<span ="noattr">10</span>',                      // missing attribute name
  '<span ::="test">11</span>',                      // bad namespace prefix
  '<span xmlns:="urn:x-test:test">12</span>',       // missing namespace prefix
  '<span xmlns:xmlns="">13</span>',                 // invalid namespace prefix
  '<span data-test=testing>14</span>',              // unquoted attribute value
  '15<span',                                        // bad start tag
  '<8:test xmlns:8="urn:x-test:test">16</8:test>',  // invalid namespace prefix
  '<span xmlns:p1 xmlns:p2="urn:x-test:test"/>17',  // missing namespace URI
].forEach(fragment => {
  test(() => {
    var document_string = xhtml_prologue + fragment + xhtml_epilogue;
    var doc = (new DOMParser).parseFromString(document_string, "application/xhtml+xml");
    var parsererrors = doc.getElementsByTagName("parsererror");
    assert_equals(parsererrors.length, 1, 'expecting one parsererror');
  }, document.title + ', ' + fragment);
});

[
  'text/xml',
  'application/xml',
  'application/xhtml+xml',
  'image/svg+xml'
].forEach(mimeType => {
  test(() => {
    const doc = (new DOMParser()).parseFromString('<span x:test="testing">1</span>', mimeType);
    assert_equals(doc.contentType, mimeType);
  }, `${mimeType} is preserved in the error document`);
})
</script>