1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tests/unit/test_bug381412.johab.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +const charset = "x-johab"; 1.5 + 1.6 +function dumpStrings(inString, outString) { 1.7 + var dispIn = ""; 1.8 + var dispOut = ""; 1.9 + var i; 1.10 + for (i = 0; i < inString.length; ++i) { 1.11 + dispIn += " x" + inString.charCodeAt(i).toString(16); 1.12 + } 1.13 + if (outString.length == 0) { 1.14 + dispOut = "<empty>"; 1.15 + } else { 1.16 + for (i = 0; i < outString.length; ++i) { 1.17 + dispOut += " x" + outString.charCodeAt(i).toString(16); 1.18 + } 1.19 + } 1.20 + dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n"); 1.21 +} 1.22 + 1.23 +function error(inString, outString, msg){ 1.24 + dumpStrings(inString, outString); 1.25 + do_throw("security risk: " + msg); 1.26 +} 1.27 + 1.28 +function run_test() { 1.29 + var ScriptableUnicodeConverter = 1.30 + Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter", 1.31 + "nsIScriptableUnicodeConverter"); 1.32 + 1.33 + var converter = new ScriptableUnicodeConverter(); 1.34 + converter.charset = charset; 1.35 + 1.36 + var leadByte, trailByte; 1.37 + var inString; 1.38 + for (leadByte = 1; leadByte < 0x100; ++leadByte) { 1.39 + for (trailByte = 1; trailByte < 0x100; ++trailByte) { 1.40 + inString = String.fromCharCode(leadByte, trailByte, 65); 1.41 + var outString = converter.ConvertToUnicode(inString) + converter.Finish(); 1.42 + switch (outString.length) { 1.43 + case 1: 1.44 + error(inString, outString, "2 byte sequence eaten"); 1.45 + break; 1.46 + case 2: 1.47 + if (outString.charCodeAt(0) < 0x80 && 1.48 + outString.charCodeAt(1) < 0x80) { 1.49 + error(inString, outString, "2 byte sequence converted to 1 ASCII"); 1.50 + } 1.51 + break; 1.52 + case 3: 1.53 + if (outString != inString && 1.54 + outString.charCodeAt(0) < 0x80 && 1.55 + outString.charCodeAt(1) < 0x80) { 1.56 + error(inString, outString, 1.57 + "2 byte sequence converted to 2 ASCII"); 1.58 + } 1.59 + break; 1.60 + } 1.61 + } 1.62 + } 1.63 +}