tor-browser

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

unicode.html (1780B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Blob/Unicode interaction: normalization and encoding</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script>
      7 'use strict';
      8 
      9 const OMICRON_WITH_OXIA = '\u1F79'; // NFC normalized to U+3CC
     10 const CONTAINS_UNPAIRED_SURROGATES = 'abc\uDC00def\uD800ghi';
     11 const REPLACED = 'abc\uFFFDdef\uFFFDghi';
     12 
     13 function readBlobAsPromise(blob) {
     14  return new Promise((resolve, reject) => {
     15    const reader = new FileReader();
     16    reader.readAsText(blob);
     17    reader.onload = () => resolve(reader.result);
     18    reader.onerror = () => reject(reader.error);
     19  });
     20 }
     21 
     22 promise_test(async t => {
     23  const blob = new Blob([OMICRON_WITH_OXIA]);
     24  const result = await readBlobAsPromise(blob);
     25  assert_equals(result, OMICRON_WITH_OXIA, 'String should not be normalized');
     26 }, 'Test that strings are not NFC normalized by Blob constructor');
     27 
     28 promise_test(async t => {
     29  const file = new File([OMICRON_WITH_OXIA], 'name');
     30  const result = await readBlobAsPromise(file);
     31  assert_equals(result, OMICRON_WITH_OXIA, 'String should not be normalized');
     32 }, 'Test that strings are not NFC normalized by File constructor');
     33 
     34 promise_test(async t => {
     35  const blob = new Blob([CONTAINS_UNPAIRED_SURROGATES]);
     36  const result = await readBlobAsPromise(blob);
     37  assert_equals(result, REPLACED, 'Unpaired surrogates should be replaced.');
     38 }, 'Test that unpaired surrogates are replaced by Blob constructor');
     39 
     40 promise_test(async t => {
     41  const file = new File([CONTAINS_UNPAIRED_SURROGATES], 'name');
     42  const result = await readBlobAsPromise(file);
     43  assert_equals(result, REPLACED, 'Unpaired surrogates should be replaced.');
     44 }, 'Test that unpaired surrogates are replaced by File constructor');
     45 
     46 </script>