File: test_xml_mislabeled.html

package info (click to toggle)
thunderbird 1%3A91.13.0-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,953,400 kB
  • sloc: cpp: 6,084,049; javascript: 4,790,441; ansic: 3,341,496; python: 862,958; asm: 366,542; xml: 204,277; java: 152,477; sh: 111,436; makefile: 21,388; perl: 15,312; yacc: 4,583; objc: 3,026; lex: 1,720; exp: 762; pascal: 635; awk: 564; sql: 453; php: 436; lisp: 432; ruby: 99; sed: 69; csh: 45
file content (62 lines) | stat: -rw-r--r-- 2,483 bytes parent folder | download | duplicates (28)
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
<!DOCTYPE html><meta charset=utf-8>
<title>Test for mislabeled or unlabeled XML entities with U+xxD8</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
<body>
<script class="testbody">
"use strict";

SimpleTest.waitForExplicitFinish();

var declaredEncodings = [null, "utf-8", "uTf-8", "UTF-8", "utf-16", "uTf-16", "UTF-16"];
var actualEncodings = ["utf-8", "utf-16be", "utf-16le"];
var i = 0, j = 0;
testxhr(declaredEncodings[i], actualEncodings[j]);

function testxhr(declaredEncoding, actualEncoding) {
  // utf-16 XML requres the BOM
  var bom = actualEncoding.startsWith("utf-16") ? "\uFEFF" : "";
  var xmlDecl = declaredEncoding ? '<?xml version="1.0" encoding="' + declaredEncoding + '" ?>\n' : "";
  // The test string need to contain U+xxD8 (bug 860180)
  var xmlString = bom + xmlDecl + "<test>testハヒフヘホ</test>";
  var xml = new TextEncoder(actualEncoding).encode(xmlString);
  var description = declaredEncoding ? " labeled with " + declaredEncoding : " without XML declaration";
  if (!declaredEncoding || actualEncoding !== declaredEncoding.toLowerCase()) {
    description += " but actually encoded with " + actualEncoding;
  }
  var xhr = new XMLHttpRequest();
  var url = URL.createObjectURL(new Blob([xml], {type: "text/xml"}));
  xhr.open("GET", url);
  xhr.send();
  xhr.onload = xhr.onerror = function(e) {
    URL.revokeObjectURL(url);
    is(e.type, "load", "xhr loading should succeed for XML" + description);
    is(xhr.responseXML.documentElement.textContent, "testハヒフヘホ",
       "response should be available for XML" + description);
    testiframe(description, xml);
  };
}

function testiframe(description, xml) {
  var iframe = document.createElement("iframe");
  var url = URL.createObjectURL(new Blob([xml], {type: "text/xml"}));
  iframe.src = url;
  iframe.onload = iframe.onerror = function(e) {
    URL.revokeObjectURL(url);
    is(e.type, "load", "iframe loading should succeed for XML" + description);
    is(iframe.contentDocument.documentElement.textContent, "testハヒフヘホ",
       "iframe content should be available for XML" + description);
    if (++i >= declaredEncodings.length) {
      i = 0;
      if (++j >= actualEncodings.length) {
        SimpleTest.finish();
        return;
      }
    }
    testxhr(declaredEncodings[i], actualEncodings[j]);
  };
  document.body.appendChild(iframe);
}
</script>
<div id="display"></div>
</body>