intl/uconv/tests/unit/test_bug715319.dbcs.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // 2-byte charsets:
michael@0 2 const charsets = [ "Big5", "EUC-KR", "x-euc-tw", "x-johab" ]
michael@0 3 const ScriptableUnicodeConverter =
michael@0 4 Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
michael@0 5 "nsIScriptableUnicodeConverter");
michael@0 6 var gConverter;
michael@0 7
michael@0 8 function error(inString, outString, msg) {
michael@0 9 var dispIn = "";
michael@0 10 var dispOut = "";
michael@0 11 var i;
michael@0 12 for (i = 0; i < inString.length; ++i) {
michael@0 13 dispIn += " x" + inString.charCodeAt(i).toString(16);
michael@0 14 }
michael@0 15 if (outString.length == 0) {
michael@0 16 dispOut = "<empty>";
michael@0 17 } else {
michael@0 18 for (i = 0; i < outString.length; ++i) {
michael@0 19 dispOut += " x" + outString.charCodeAt(i).toString(16);
michael@0 20 }
michael@0 21 }
michael@0 22 dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
michael@0 23 do_throw("security risk: " + msg);
michael@0 24 }
michael@0 25
michael@0 26 function IsASCII(charCode) {
michael@0 27 return (charCode <= 0x7e);
michael@0 28 }
michael@0 29
michael@0 30 function test(inString) {
michael@0 31 var outString = gConverter.ConvertToUnicode(inString) +
michael@0 32 gConverter.Finish();
michael@0 33
michael@0 34 var outLen = outString.length;
michael@0 35
michael@0 36 if (IsASCII(inString.charCodeAt(1)) &&
michael@0 37 (outLen < 4 || outString.charCodeAt(outLen - 4) == 0xFFFD)) {
michael@0 38 error(inString, outString, "ASCII input eaten in " + gConverter.charset);
michael@0 39 }
michael@0 40 }
michael@0 41
michael@0 42 function run_test() {
michael@0 43 gConverter = new ScriptableUnicodeConverter();
michael@0 44 for (var i = 0; i < charsets.length; ++i) {
michael@0 45 gConverter.charset = charsets[i];
michael@0 46
michael@0 47 var byte1, byte2;
michael@0 48 for (byte1 = 1; byte1 < 0x100; ++byte1) {
michael@0 49 for (byte2 = 1; byte2 < 0x100; ++byte2) {
michael@0 50 test(String.fromCharCode(byte1, byte2) + "foo");
michael@0 51 }
michael@0 52 }
michael@0 53 }
michael@0 54 }

mercurial