1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tests/unit/test_bug715319.dbcs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +// 2-byte charsets: 1.5 +const charsets = [ "Big5", "EUC-KR", "x-euc-tw", "x-johab" ] 1.6 +const ScriptableUnicodeConverter = 1.7 + Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter", 1.8 + "nsIScriptableUnicodeConverter"); 1.9 +var gConverter; 1.10 + 1.11 +function error(inString, outString, msg) { 1.12 + var dispIn = ""; 1.13 + var dispOut = ""; 1.14 + var i; 1.15 + for (i = 0; i < inString.length; ++i) { 1.16 + dispIn += " x" + inString.charCodeAt(i).toString(16); 1.17 + } 1.18 + if (outString.length == 0) { 1.19 + dispOut = "<empty>"; 1.20 + } else { 1.21 + for (i = 0; i < outString.length; ++i) { 1.22 + dispOut += " x" + outString.charCodeAt(i).toString(16); 1.23 + } 1.24 + } 1.25 + dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n"); 1.26 + do_throw("security risk: " + msg); 1.27 +} 1.28 + 1.29 +function IsASCII(charCode) { 1.30 + return (charCode <= 0x7e); 1.31 +} 1.32 + 1.33 +function test(inString) { 1.34 + var outString = gConverter.ConvertToUnicode(inString) + 1.35 + gConverter.Finish(); 1.36 + 1.37 + var outLen = outString.length; 1.38 + 1.39 + if (IsASCII(inString.charCodeAt(1)) && 1.40 + (outLen < 4 || outString.charCodeAt(outLen - 4) == 0xFFFD)) { 1.41 + error(inString, outString, "ASCII input eaten in " + gConverter.charset); 1.42 + } 1.43 +} 1.44 + 1.45 +function run_test() { 1.46 + gConverter = new ScriptableUnicodeConverter(); 1.47 + for (var i = 0; i < charsets.length; ++i) { 1.48 + gConverter.charset = charsets[i]; 1.49 + 1.50 + var byte1, byte2; 1.51 + for (byte1 = 1; byte1 < 0x100; ++byte1) { 1.52 + for (byte2 = 1; byte2 < 0x100; ++byte2) { 1.53 + test(String.fromCharCode(byte1, byte2) + "foo"); 1.54 + } 1.55 + } 1.56 + } 1.57 +}