tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

responsetext-decoding.htm (4798B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8">
      5    <title>XMLHttpRequest: responseText decoding</title>
      6    <script src="/resources/testharness.js"></script>
      7    <script src="/resources/testharnessreport.js"></script>
      8  </head>
      9  <body>
     10    <script>
     11      function create_html(content) {
     12        return "<!doctype html><meta charset=windows-1252><x>" + content + "</x>";
     13      }
     14      function create_encoded_html(encoded_content) {
     15        return encodeURIComponent("<!doctype html><meta charset=windows-1252><x>") + encoded_content + encodeURIComponent("<\/x>");
     16      }
     17      function create_xml(content) {
     18        return "<?xml version='1.0' encoding='windows-1252'?><x>" + content + "</x>";
     19      }
     20      function create_encoded_xml(encoded_content) {
     21        return encodeURIComponent("<?xml version='1.0' encoding='windows-1252'?><x>") + encoded_content + encodeURIComponent("<\/x>");
     22      }
     23      function request(type, input, output, responseType) {
     24        async_test((test) => {
     25          const client = new XMLHttpRequest();
     26          if (responseType !== undefined) {
     27            client.responseType = responseType;
     28          }
     29          client.open("GET", "resources/status.py?content=" + input + "&type=" + encodeURIComponent(type), true);
     30          client.onload = test.step_func_done(() => {
     31            assert_equals(client.responseText, output);
     32          })
     33          client.send(null);
     34        }, document.title + " (" + type + " " + input + " " + (responseType ? " " + responseType : "empty") + ")");
     35      }
     36 
     37      const encoded_content = "%e6%a9%9f";
     38      const decoded_as_windows_1252 = "\u00e6\u00a9\u0178";
     39      const decoded_as_utf_8 = "\u6a5f";
     40      const encoded_xml = create_encoded_xml(encoded_content);
     41      const encoded_html = create_encoded_html(encoded_content);
     42      const xml_decoded_as_windows_1252 = create_xml(decoded_as_windows_1252);
     43      const xml_decoded_as_utf_8 = create_xml(decoded_as_utf_8);
     44      const html_decoded_as_windows_1252 = create_html(decoded_as_windows_1252);
     45      const html_decoded_as_utf_8 = create_html(decoded_as_utf_8);
     46 
     47      // "default" response type
     48      // An XML-ish response is sniffed.
     49      request("application/xml", encoded_xml, xml_decoded_as_windows_1252);
     50      // An HTML-ish response isn't sniffed.
     51      request("text/html", encoded_html, html_decoded_as_utf_8);
     52      request("application/xml;charset=utf-8", encoded_xml, xml_decoded_as_utf_8);
     53      request("application/xml;charset=windows-1252", encoded_xml, xml_decoded_as_windows_1252);
     54      request("text/html;charset=utf-8", encoded_html, html_decoded_as_utf_8);
     55      request("text/html;charset=windows-1252", encoded_html, html_decoded_as_windows_1252);
     56      request("text/plain;charset=windows-1252", "%FF", "\u00FF");
     57      request("text/plain", "%FF", "\uFFFD");
     58      request("text/plain", "%FE%FF", "");
     59      request("text/plain", "%FE%FF%FE%FF", "\uFEFF");
     60      request("text/plain", "%EF%BB%BF", "");
     61      request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF");
     62      request("text/plain", "%C2", "\uFFFD");
     63      request("text/xml", "%FE%FF", "");
     64      request("text/xml", "%FE%FF%FE%FF", "\uFEFF");
     65      request("text/xml", "%EF%BB%BF", "");
     66      request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF");
     67      request("text/plain", "%E3%81%B2", "\u3072");
     68 
     69      // "text" response type
     70      // An XML-ish response isn't sniffed.
     71      request("application/xml", encoded_xml, xml_decoded_as_utf_8, "text");
     72      // An HTML-ish response isn't sniffed.
     73      request("text/html", encoded_html, html_decoded_as_utf_8, "text");
     74      request("application/xml;charset=utf-8", encoded_xml, xml_decoded_as_utf_8, "text");
     75      request("application/xml;charset=windows-1252", encoded_xml, xml_decoded_as_windows_1252, "text");
     76      request("text/html;charset=utf-8", encoded_html, html_decoded_as_utf_8, "text");
     77      request("text/html;charset=windows-1252", encoded_html, html_decoded_as_windows_1252, "text");
     78      request("text/plain;charset=windows-1252", "%FF", "\u00FF", "text");
     79      request("text/plain", "%FF", "\uFFFD", "text");
     80      request("text/plain", "%FE%FF", "", "text");
     81      request("text/plain", "%FE%FF%FE%FF", "\uFEFF", "text");
     82      request("text/plain", "%EF%BB%BF", "", "text");
     83      request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
     84      request("text/plain", "%C2", "\uFFFD", "text");
     85      request("text/plain;charset=bogus", "%C2", "\uFFFD", "text");
     86      request("text/xml", "%FE%FF", "", "text");
     87      request("text/xml", "%FE%FF%FE%FF", "\uFEFF", "text");
     88      request("text/xml", "%EF%BB%BF", "", "text");
     89      request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
     90      request("text/plain", "%E3%81%B2", "\u3072", "text");
     91    </script>
     92  </body>
     93 </html>