intl/uconv/tests/unit/test_bug381412.johab.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 const charset = "x-johab";
michael@0 2
michael@0 3 function dumpStrings(inString, outString) {
michael@0 4 var dispIn = "";
michael@0 5 var dispOut = "";
michael@0 6 var i;
michael@0 7 for (i = 0; i < inString.length; ++i) {
michael@0 8 dispIn += " x" + inString.charCodeAt(i).toString(16);
michael@0 9 }
michael@0 10 if (outString.length == 0) {
michael@0 11 dispOut = "<empty>";
michael@0 12 } else {
michael@0 13 for (i = 0; i < outString.length; ++i) {
michael@0 14 dispOut += " x" + outString.charCodeAt(i).toString(16);
michael@0 15 }
michael@0 16 }
michael@0 17 dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
michael@0 18 }
michael@0 19
michael@0 20 function error(inString, outString, msg){
michael@0 21 dumpStrings(inString, outString);
michael@0 22 do_throw("security risk: " + msg);
michael@0 23 }
michael@0 24
michael@0 25 function run_test() {
michael@0 26 var ScriptableUnicodeConverter =
michael@0 27 Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
michael@0 28 "nsIScriptableUnicodeConverter");
michael@0 29
michael@0 30 var converter = new ScriptableUnicodeConverter();
michael@0 31 converter.charset = charset;
michael@0 32
michael@0 33 var leadByte, trailByte;
michael@0 34 var inString;
michael@0 35 for (leadByte = 1; leadByte < 0x100; ++leadByte) {
michael@0 36 for (trailByte = 1; trailByte < 0x100; ++trailByte) {
michael@0 37 inString = String.fromCharCode(leadByte, trailByte, 65);
michael@0 38 var outString = converter.ConvertToUnicode(inString) + converter.Finish();
michael@0 39 switch (outString.length) {
michael@0 40 case 1:
michael@0 41 error(inString, outString, "2 byte sequence eaten");
michael@0 42 break;
michael@0 43 case 2:
michael@0 44 if (outString.charCodeAt(0) < 0x80 &&
michael@0 45 outString.charCodeAt(1) < 0x80) {
michael@0 46 error(inString, outString, "2 byte sequence converted to 1 ASCII");
michael@0 47 }
michael@0 48 break;
michael@0 49 case 3:
michael@0 50 if (outString != inString &&
michael@0 51 outString.charCodeAt(0) < 0x80 &&
michael@0 52 outString.charCodeAt(1) < 0x80) {
michael@0 53 error(inString, outString,
michael@0 54 "2 byte sequence converted to 2 ASCII");
michael@0 55 }
michael@0 56 break;
michael@0 57 }
michael@0 58 }
michael@0 59 }
michael@0 60 }

mercurial