tor-browser

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

test_bug479413.js (1120B)


      1 /**
      2 * Test for unassigned code points in IDNs (RFC 3454 section 7)
      3 */
      4 
      5 "use strict";
      6 
      7 var idnService;
      8 
      9 function expected_pass(inputIDN) {
     10  var displayIDN = idnService.convertToDisplayIDN(inputIDN);
     11  Assert.equal(displayIDN, inputIDN);
     12 }
     13 
     14 function expected_fail(inputIDN) {
     15  var displayIDN = "";
     16 
     17  try {
     18    displayIDN = idnService.convertToDisplayIDN(inputIDN);
     19  } catch (e) {}
     20 
     21  Assert.notEqual(displayIDN, inputIDN);
     22 }
     23 
     24 function run_test() {
     25  idnService = Cc["@mozilla.org/network/idn-service;1"].getService(
     26    Ci.nsIIDNService
     27  );
     28 
     29  // assigned code point
     30  expected_pass("foo\u0101bar.com");
     31 
     32  // assigned code point in punycode. Should *fail* because the URL will be
     33  // converted to Unicode for display
     34  expected_fail("xn--foobar-5za.com");
     35 
     36  // unassigned code point
     37  expected_fail("foo\u3040bar.com");
     38 
     39  // unassigned code point in punycode. Should *fail* because Punycode
     40  // is decoded and checked.
     41  expected_fail("xn--foobar-533e.com");
     42 
     43  // code point assigned since Unicode 3.0
     44  // XXX This test will unexpectedly pass when we update to IDNAbis
     45  expected_fail("foo\u0370bar.com");
     46 }