summaryrefslogtreecommitdiffstats
path: root/intl/uconv/tests/unit/test_bug381412.Big5.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /intl/uconv/tests/unit/test_bug381412.Big5.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'intl/uconv/tests/unit/test_bug381412.Big5.js')
-rw-r--r--intl/uconv/tests/unit/test_bug381412.Big5.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/intl/uconv/tests/unit/test_bug381412.Big5.js b/intl/uconv/tests/unit/test_bug381412.Big5.js
new file mode 100644
index 000000000..d42976d5b
--- /dev/null
+++ b/intl/uconv/tests/unit/test_bug381412.Big5.js
@@ -0,0 +1,60 @@
+const charset = "Big5";
+
+function dumpStrings(inString, outString) {
+ var dispIn = "";
+ var dispOut = "";
+ var i;
+ for (i = 0; i < inString.length; ++i) {
+ dispIn += " x" + inString.charCodeAt(i).toString(16);
+ }
+ if (outString.length == 0) {
+ dispOut = "<empty>";
+ } else {
+ for (i = 0; i < outString.length; ++i) {
+ dispOut += " x" + outString.charCodeAt(i).toString(16);
+ }
+ }
+ dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n");
+}
+
+function error(inString, outString, msg){
+ dumpStrings(inString, outString);
+ do_throw("security risk: " + msg);
+}
+
+function run_test() {
+ var ScriptableUnicodeConverter =
+ Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter",
+ "nsIScriptableUnicodeConverter");
+
+ var converter = new ScriptableUnicodeConverter();
+ converter.charset = charset;
+
+ var leadByte, trailByte;
+ var inString;
+ for (leadByte = 1; leadByte < 0x100; ++leadByte) {
+ for (trailByte = 1; trailByte < 0x100; ++trailByte) {
+ inString = String.fromCharCode(leadByte, trailByte, 65);
+ var outString = converter.ConvertToUnicode(inString) + converter.Finish();
+ switch (outString.length) {
+ case 1:
+ error(inString, outString, "2 byte sequence eaten");
+ break;
+ case 2:
+ if (outString.charCodeAt(0) < 0x80 &&
+ outString.charCodeAt(1) < 0x80) {
+ error(inString, outString, "2 byte sequence converted to 1 ASCII");
+ }
+ break;
+ case 3:
+ if (outString != inString &&
+ outString.charCodeAt(0) < 0x80 &&
+ outString.charCodeAt(1) < 0x80) {
+ error(inString, outString,
+ "2 byte sequence converted to 2 ASCII");
+ }
+ break;
+ }
+ }
+ }
+}