|
1 /** |
|
2 * Test for Bidi restrictions on IDNs from RFC 3454 |
|
3 */ |
|
4 |
|
5 var Cc = Components.classes; |
|
6 var Ci = Components.interfaces; |
|
7 var idnService; |
|
8 |
|
9 function expected_pass(inputIDN) |
|
10 { |
|
11 var isASCII = {}; |
|
12 var displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); |
|
13 do_check_eq(displayIDN, inputIDN); |
|
14 } |
|
15 |
|
16 function expected_fail(inputIDN) |
|
17 { |
|
18 var isASCII = {}; |
|
19 var displayIDN = ""; |
|
20 |
|
21 try { |
|
22 displayIDN = idnService.convertToDisplayIDN(inputIDN, isASCII); |
|
23 } |
|
24 catch(e) {} |
|
25 |
|
26 do_check_neq(displayIDN, inputIDN); |
|
27 } |
|
28 |
|
29 function run_test() { |
|
30 // add an IDN whitelist pref |
|
31 var pbi = Cc["@mozilla.org/preferences-service;1"] |
|
32 .getService(Ci.nsIPrefBranch); |
|
33 pbi.setBoolPref("network.IDN.whitelist.com", true); |
|
34 |
|
35 idnService = Cc["@mozilla.org/network/idn-service;1"] |
|
36 .getService(Ci.nsIIDNService); |
|
37 /* |
|
38 * In any profile that specifies bidirectional character handling, all |
|
39 * three of the following requirements MUST be met: |
|
40 * |
|
41 * 1) The characters in section 5.8 MUST be prohibited. |
|
42 */ |
|
43 |
|
44 // 0340; COMBINING GRAVE TONE MARK |
|
45 expected_fail("foo\u0340bar.com"); |
|
46 // 0341; COMBINING ACUTE TONE MARK |
|
47 expected_fail("foo\u0341bar.com"); |
|
48 // 200E; LEFT-TO-RIGHT MARK |
|
49 expected_fail("foo\200ebar.com"); |
|
50 // 200F; RIGHT-TO-LEFT MARK |
|
51 // Note: this is an RTL IDN so that it doesn't fail test 2) below |
|
52 expected_fail("\u200f\u0645\u062B\u0627\u0644.\u0622\u0632\u0645\u0627\u06CC\u0634\u06CC"); |
|
53 // 202A; LEFT-TO-RIGHT EMBEDDING |
|
54 expected_fail("foo\u202abar.com"); |
|
55 // 202B; RIGHT-TO-LEFT EMBEDDING |
|
56 expected_fail("foo\u202bbar.com"); |
|
57 // 202C; POP DIRECTIONAL FORMATTING |
|
58 expected_fail("foo\u202cbar.com"); |
|
59 // 202D; LEFT-TO-RIGHT OVERRIDE |
|
60 expected_fail("foo\u202dbar.com"); |
|
61 // 202E; RIGHT-TO-LEFT OVERRIDE |
|
62 expected_fail("foo\u202ebar.com"); |
|
63 // 206A; INHIBIT SYMMETRIC SWAPPING |
|
64 expected_fail("foo\u206abar.com"); |
|
65 // 206B; ACTIVATE SYMMETRIC SWAPPING |
|
66 expected_fail("foo\u206bbar.com"); |
|
67 // 206C; INHIBIT ARABIC FORM SHAPING |
|
68 expected_fail("foo\u206cbar.com"); |
|
69 // 206D; ACTIVATE ARABIC FORM SHAPING |
|
70 expected_fail("foo\u206dbar.com"); |
|
71 // 206E; NATIONAL DIGIT SHAPES |
|
72 expected_fail("foo\u206ebar.com"); |
|
73 // 206F; NOMINAL DIGIT SHAPES |
|
74 expected_fail("foo\u206fbar.com"); |
|
75 |
|
76 /* |
|
77 * 2) If a string contains any RandALCat character, the string MUST NOT |
|
78 * contain any LCat character. |
|
79 */ |
|
80 |
|
81 // www.מיץpetel.com is invalid |
|
82 expected_fail("www.\u05DE\u05D9\u05E5petel.com"); |
|
83 // But www.מיץפטל.com is fine because the ltr and rtl characters are in |
|
84 // different labels |
|
85 expected_pass("www.\u05DE\u05D9\u05E5\u05E4\u05D8\u05DC.com"); |
|
86 |
|
87 /* |
|
88 * 3) If a string contains any RandALCat character, a RandALCat |
|
89 * character MUST be the first character of the string, and a |
|
90 * RandALCat character MUST be the last character of the string. |
|
91 */ |
|
92 |
|
93 // www.1מיץ.com is invalid |
|
94 expected_fail("www.1\u05DE\u05D9\u05E5.com"); |
|
95 // www.מיץ1.com is invalid |
|
96 expected_fail("www.\u05DE\u05D9\u05E51.com"); |
|
97 // But www.מיץ1פטל.com is fine |
|
98 expected_pass("www.\u05DE\u05D9\u05E51\u05E4\u05D8\u05DC.com"); |
|
99 } |
|
100 |