tor-browser

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

test_bug427957.js (3036B)


      1 /**
      2 * Test for Bidi restrictions on IDNs from RFC 3454
      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   * In any profile that specifies bidirectional character handling, all
     30   * three of the following requirements MUST be met:
     31   *
     32   * 1) The characters in section 5.8 MUST be prohibited.
     33   */
     34 
     35  // 0340; COMBINING GRAVE TONE MARK
     36  expected_fail("foo\u0340bar.com");
     37  // 0341; COMBINING ACUTE TONE MARK
     38  expected_fail("foo\u0341bar.com");
     39  // 200E; LEFT-TO-RIGHT MARK
     40  expected_fail("foo\u200ebar.com");
     41  // 200F; RIGHT-TO-LEFT MARK
     42  //  Note: this is an RTL IDN so that it doesn't fail test 2) below
     43  expected_fail(
     44    "\u200f\u0645\u062B\u0627\u0644.\u0622\u0632\u0645\u0627\u06CC\u0634\u06CC"
     45  );
     46  // 202A; LEFT-TO-RIGHT EMBEDDING
     47  expected_fail("foo\u202abar.com");
     48  // 202B; RIGHT-TO-LEFT EMBEDDING
     49  expected_fail("foo\u202bbar.com");
     50  // 202C; POP DIRECTIONAL FORMATTING
     51  expected_fail("foo\u202cbar.com");
     52  // 202D; LEFT-TO-RIGHT OVERRIDE
     53  expected_fail("foo\u202dbar.com");
     54  // 202E; RIGHT-TO-LEFT OVERRIDE
     55  expected_fail("foo\u202ebar.com");
     56  // 206A; INHIBIT SYMMETRIC SWAPPING
     57  expected_fail("foo\u206abar.com");
     58  // 206B; ACTIVATE SYMMETRIC SWAPPING
     59  expected_fail("foo\u206bbar.com");
     60  // 206C; INHIBIT ARABIC FORM SHAPING
     61  expected_fail("foo\u206cbar.com");
     62  // 206D; ACTIVATE ARABIC FORM SHAPING
     63  expected_fail("foo\u206dbar.com");
     64  // 206E; NATIONAL DIGIT SHAPES
     65  expected_fail("foo\u206ebar.com");
     66  // 206F; NOMINAL DIGIT SHAPES
     67  expected_fail("foo\u206fbar.com");
     68 
     69  /*
     70   * 2) If a string contains any RandALCat character, the string MUST NOT
     71   *    contain any LCat character.
     72   */
     73 
     74  // www.מיץpetel.com is invalid
     75  expected_fail("www.\u05DE\u05D9\u05E5petel.com");
     76  // But www.מיץפטל.com is fine because the ltr and rtl characters are in
     77  // different labels
     78  expected_pass("www.\u05DE\u05D9\u05E5\u05E4\u05D8\u05DC.com");
     79 
     80  /*
     81   * 3) If a string contains any RandALCat character, a RandALCat
     82   *    character MUST be the first character of the string, and a
     83   *    RandALCat character MUST be the last character of the string.
     84   */
     85 
     86  // www.1מיץ.com is invalid
     87  expected_fail("www.1\u05DE\u05D9\u05E5.com");
     88  // www.!מיץ.com is invalid
     89  expected_fail("www.!\u05DE\u05D9\u05E5.com");
     90  // www.מיץ!.com is invalid
     91  expected_fail("www.\u05DE\u05D9\u05E5!.com");
     92 
     93  // XXX TODO: add a test for an RTL label ending with a digit. This was
     94  //           invalid in IDNA2003 but became valid in IDNA2008
     95 
     96  // But www.מיץ1פטל.com is fine
     97  expected_pass("www.\u05DE\u05D9\u05E51\u05E4\u05D8\u05DC.com");
     98 }