michael@0: /** michael@0: * Test for Bidi restrictions on IDNs from RFC 3454 michael@0: */ michael@0: michael@0: var Cc = Components.classes; michael@0: var Ci = Components.interfaces; michael@0: var idnService; michael@0: michael@0: function expected_pass(inputIDN) michael@0: { michael@0: var isASCII = {}; michael@0: var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); michael@0: do_check_eq(displayIDN, inputIDN); michael@0: } michael@0: michael@0: function expected_fail(inputIDN) michael@0: { michael@0: var isASCII = {}; michael@0: var displayIDN = ""; michael@0: michael@0: try { michael@0: displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); michael@0: } michael@0: catch(e) {} michael@0: michael@0: do_check_neq(displayIDN, inputIDN); michael@0: } michael@0: michael@0: function run_test() { michael@0: // add an IDN whitelist pref michael@0: var pbi = Cc["@mozilla.org/preferences-service;1"] michael@0: .getService(Ci.nsIPrefBranch); michael@0: pbi.setBoolPref("network.IDN.whitelist.com", true); michael@0: michael@0: idnService = Cc["@mozilla.org/network/idn-service;1"] michael@0: .getService(Ci.nsIIDNService); michael@0: /* michael@0: * In any profile that specifies bidirectional character handling, all michael@0: * three of the following requirements MUST be met: michael@0: * michael@0: * 1) The characters in section 5.8 MUST be prohibited. michael@0: */ michael@0: michael@0: // 0340; COMBINING GRAVE TONE MARK michael@0: expected_fail("foo\u0340bar.com"); michael@0: // 0341; COMBINING ACUTE TONE MARK michael@0: expected_fail("foo\u0341bar.com"); michael@0: // 200E; LEFT-TO-RIGHT MARK michael@0: expected_fail("foo\200ebar.com"); michael@0: // 200F; RIGHT-TO-LEFT MARK michael@0: // Note: this is an RTL IDN so that it doesn't fail test 2) below michael@0: expected_fail("\u200f\u0645\u062B\u0627\u0644.\u0622\u0632\u0645\u0627\u06CC\u0634\u06CC"); michael@0: // 202A; LEFT-TO-RIGHT EMBEDDING michael@0: expected_fail("foo\u202abar.com"); michael@0: // 202B; RIGHT-TO-LEFT EMBEDDING michael@0: expected_fail("foo\u202bbar.com"); michael@0: // 202C; POP DIRECTIONAL FORMATTING michael@0: expected_fail("foo\u202cbar.com"); michael@0: // 202D; LEFT-TO-RIGHT OVERRIDE michael@0: expected_fail("foo\u202dbar.com"); michael@0: // 202E; RIGHT-TO-LEFT OVERRIDE michael@0: expected_fail("foo\u202ebar.com"); michael@0: // 206A; INHIBIT SYMMETRIC SWAPPING michael@0: expected_fail("foo\u206abar.com"); michael@0: // 206B; ACTIVATE SYMMETRIC SWAPPING michael@0: expected_fail("foo\u206bbar.com"); michael@0: // 206C; INHIBIT ARABIC FORM SHAPING michael@0: expected_fail("foo\u206cbar.com"); michael@0: // 206D; ACTIVATE ARABIC FORM SHAPING michael@0: expected_fail("foo\u206dbar.com"); michael@0: // 206E; NATIONAL DIGIT SHAPES michael@0: expected_fail("foo\u206ebar.com"); michael@0: // 206F; NOMINAL DIGIT SHAPES michael@0: expected_fail("foo\u206fbar.com"); michael@0: michael@0: /* michael@0: * 2) If a string contains any RandALCat character, the string MUST NOT michael@0: * contain any LCat character. michael@0: */ michael@0: michael@0: // www.מיץpetel.com is invalid michael@0: expected_fail("www.\u05DE\u05D9\u05E5petel.com"); michael@0: // But www.מיץפטל.com is fine because the ltr and rtl characters are in michael@0: // different labels michael@0: expected_pass("www.\u05DE\u05D9\u05E5\u05E4\u05D8\u05DC.com"); michael@0: michael@0: /* michael@0: * 3) If a string contains any RandALCat character, a RandALCat michael@0: * character MUST be the first character of the string, and a michael@0: * RandALCat character MUST be the last character of the string. michael@0: */ michael@0: michael@0: // www.1מיץ.com is invalid michael@0: expected_fail("www.1\u05DE\u05D9\u05E5.com"); michael@0: // www.מיץ1.com is invalid michael@0: expected_fail("www.\u05DE\u05D9\u05E51.com"); michael@0: // But www.מיץ1פטל.com is fine michael@0: expected_pass("www.\u05DE\u05D9\u05E51\u05E4\u05D8\u05DC.com"); michael@0: } michael@0: