test_idn_blacklist.js (4444B)
1 // Test that URLs containing characters in the IDN blacklist are 2 // always displayed as punycode 3 4 "use strict"; 5 6 const testcases = [ 7 // Original Punycode or 8 // normalized form 9 // 10 ["\u00BC", "xn--14-c6t"], 11 ["\u00BD", "xn--12-c6t"], 12 ["\u00BE", "xn--34-c6t"], 13 ["\u01C3", "xn--ija"], 14 ["\u02D0", "xn--6qa"], 15 ["\u0337", "xn--4ta"], 16 ["\u0338", "xn--5ta"], 17 ["\u0589", "xn--3bb"], 18 ["\u05C3", "xn--rdb"], 19 ["\u05F4", "xn--5eb"], 20 ["\u0609", "xn--rfb"], 21 ["\u060A", "xn--sfb"], 22 ["\u066A", "xn--jib"], 23 ["\u06D4", "xn--klb"], 24 ["\u0701", "xn--umb"], 25 ["\u0702", "xn--vmb"], 26 ["\u0703", "xn--wmb"], 27 ["\u0704", "xn--xmb"], 28 // This test is turned off due to https://bugzilla.mozilla.org/show_bug.cgi?id=1960300#c13. 29 // ["\u115F", "xn--osd"], 30 // This test is turned off due to https://bugzilla.mozilla.org/show_bug.cgi?id=1960300#c13. 31 // ["\u1160", "xn--psd"], 32 ["\u1735", "xn--d0e"], 33 ["\u2027", "xn--svg"], 34 ["\u2028", "xn--tvg"], 35 ["\u2029", "xn--uvg"], 36 ["\u2039", "xn--bwg"], 37 ["\u203A", "xn--cwg"], 38 ["\u2041", "xn--jwg"], 39 ["\u2044", "xn--mwg"], 40 ["\u2052", "xn--0wg"], 41 ["\u2153", "xn--13-c6t"], 42 ["\u2154", "xn--23-c6t"], 43 ["\u2155", "xn--15-c6t"], 44 ["\u2156", "xn--25-c6t"], 45 ["\u2157", "xn--35-c6t"], 46 ["\u2158", "xn--45-c6t"], 47 ["\u2159", "xn--16-c6t"], 48 ["\u215A", "xn--56-c6t"], 49 ["\u215B", "xn--18-c6t"], 50 ["\u215C", "xn--38-c6t"], 51 ["\u215D", "xn--58-c6t"], 52 ["\u215E", "xn--78-c6t"], 53 ["\u215F", "xn--1-zjn"], 54 ["\u2215", "xn--w9g"], 55 ["\u2236", "xn--ubh"], 56 ["\u23AE", "xn--lmh"], 57 ["\u2571", "xn--hzh"], 58 ["\u29F6", "xn--jxi"], 59 ["\u29F8", "xn--lxi"], 60 ["\u2AFB", "xn--z4i"], 61 ["\u2AFD", "xn--14i"], 62 ["\u2FF0", "xn--85j"], 63 ["\u2FF1", "xn--95j"], 64 ["\u2FF2", "xn--b6j"], 65 ["\u2FF3", "xn--c6j"], 66 ["\u2FF4", "xn--d6j"], 67 ["\u2FF5", "xn--e6j"], 68 ["\u2FF6", "xn--f6j"], 69 ["\u2FF7", "xn--g6j"], 70 ["\u2FF8", "xn--h6j"], 71 ["\u2FF9", "xn--i6j"], 72 ["\u2FFA", "xn--j6j"], 73 ["\u2FFB", "xn--k6j"], 74 ["\u3014", "xn--96j"], 75 ["\u3015", "xn--b7j"], 76 ["\u3033", "xn--57j"], 77 // This test is turned off due to https://bugzilla.mozilla.org/show_bug.cgi?id=1960300#c13. 78 // ["\u3164", "xn--psd"], 79 ["\u321D", "xn--()-357j35d"], 80 ["\u321E", "xn--()-357jf36c"], 81 ["\u33AE", "xn--rads-id9a"], 82 ["\u33AF", "xn--rads2-4d6b"], 83 ["\u33C6", "xn--ckg-tc2a"], 84 ["\u33DF", "xn--am-6bv"], 85 ["\uA789", "xn--058a"], 86 ["\uFE3F", "xn--x6j"], 87 ["\uFE5D", "xn--96j"], 88 ["\uFE5E", "xn--b7j"], 89 // This test is turned off due to https://bugzilla.mozilla.org/show_bug.cgi?id=1960300#c13. 90 // ["\uFFA0", "xn--psd"], 91 ["\uFFF9", "xn--vn7c"], 92 ["\uFFFA", "xn--wn7c"], 93 ["\uFFFB", "xn--xn7c"], 94 ["\uFFFC", "xn--yn7c"], 95 ["\uFFFD", "xn--zn7c"], 96 97 // Characters from the IDN blacklist that normalize to ASCII 98 // If we start using STD3ASCIIRules these will be blocked (bug 316444) 99 ["\u00A0", " "], 100 ["\u2000", " "], 101 ["\u2001", " "], 102 ["\u2002", " "], 103 ["\u2003", " "], 104 ["\u2004", " "], 105 ["\u2005", " "], 106 ["\u2006", " "], 107 ["\u2007", " "], 108 ["\u2008", " "], 109 ["\u2009", " "], 110 ["\u200A", " "], 111 ["\u2024", "."], 112 ["\u202F", " "], 113 ["\u205F", " "], 114 ["\u3000", " "], 115 ["\u3002", "."], 116 ["\uFE14", ";"], 117 ["\uFE15", "!"], 118 ["\uFF0E", "."], 119 ["\uFF0F", "/"], 120 ["\uFF61", "."], 121 122 // Characters from the IDN blacklist that are stripped by Nameprep 123 ["\u200B", ""], 124 ["\uFEFF", ""], 125 ]; 126 127 function run_test() { 128 var idnService = Cc["@mozilla.org/network/idn-service;1"].getService( 129 Ci.nsIIDNService 130 ); 131 for (var j = 0; j < testcases.length; ++j) { 132 var test = testcases[j]; 133 var URL = test[0] + ".com"; 134 var punycodeURL = test[1] + ".com"; 135 var isASCII = {}; 136 137 var result; 138 try { 139 result = idnService.convertToDisplayIDN(URL, isASCII); 140 } catch (e) { 141 continue; 142 } 143 if (punycodeURL.substr(0, 4) == "xn--") { 144 // test convertToDisplayIDN with a Unicode URL and with a 145 // Punycode URL if we have one 146 equal(escape(result), escape(punycodeURL)); 147 148 result = idnService.convertToDisplayIDN(punycodeURL, isASCII); 149 equal(escape(result), escape(punycodeURL)); 150 } else { 151 // The "punycode" URL isn't punycode. This happens in testcases 152 // where the Unicode URL has become normalized to an ASCII URL, 153 // so, even though expectedUnicode is true, the expected result 154 // is equal to punycodeURL 155 equal(escape(result), escape(punycodeURL)); 156 } 157 } 158 }