netwerk/test/unit/test_bug427957.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

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

mercurial