tor-browser

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

test_unEscapeNonAsciiURI.js (1499B)


      1 // Tests for nsITextToSubURI.unEscapeNonAsciiURI
      2 function run_test() {
      3  // Tests whether nsTextToSubURI does UTF-16 unescaping (it shouldn't)
      4  const testURI = "data:text/html,%FE%FF";
      5  Assert.equal(
      6    Services.textToSubURI.unEscapeNonAsciiURI("UTF-16", testURI),
      7    testURI
      8  );
      9 
     10  // Tests whether incomplete multibyte sequences throw.
     11  const tests = [
     12    {
     13      input: "http://example.com/?p=%E9",
     14      throws: Cr.NS_ERROR_ILLEGAL_INPUT,
     15    },
     16    {
     17      input: "http://example.com/?p=%E9%80",
     18      throws: Cr.NS_ERROR_ILLEGAL_INPUT,
     19    },
     20    {
     21      input: "http://example.com/?p=%E9%80%80",
     22      expected: "http://example.com/?p=\u9000",
     23    },
     24    {
     25      input: "http://example.com/?p=%E9e",
     26      throws: Cr.NS_ERROR_ILLEGAL_INPUT,
     27    },
     28    {
     29      input: "http://example.com/?p=%E9%E9",
     30      throws: Cr.NS_ERROR_ILLEGAL_INPUT,
     31    },
     32    {
     33      input: "http://example.com/?name=M%FCller/",
     34      throws: Cr.NS_ERROR_ILLEGAL_INPUT,
     35    },
     36    {
     37      input: "http://example.com/?name=M%C3%BCller/",
     38      expected: "http://example.com/?name=Müller/",
     39    },
     40  ];
     41 
     42  for (const t of tests) {
     43    if (t.throws !== undefined) {
     44      let thrown = undefined;
     45      try {
     46        Services.textToSubURI.unEscapeNonAsciiURI("UTF-8", t.input);
     47      } catch (e) {
     48        thrown = e.result;
     49      }
     50      Assert.equal(thrown, t.throws);
     51    } else {
     52      Assert.equal(
     53        Services.textToSubURI.unEscapeNonAsciiURI("UTF-8", t.input),
     54        t.expected
     55      );
     56    }
     57  }
     58 }