summaryrefslogtreecommitdiffstats
path: root/intl/uconv/tests/unit/test_bug563618.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/uconv/tests/unit/test_bug563618.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/uconv/tests/unit/test_bug563618.js')
-rw-r--r--intl/uconv/tests/unit/test_bug563618.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/intl/uconv/tests/unit/test_bug563618.js b/intl/uconv/tests/unit/test_bug563618.js
new file mode 100644
index 0000000000..2fa0770344
--- /dev/null
+++ b/intl/uconv/tests/unit/test_bug563618.js
@@ -0,0 +1,97 @@
+/* Test case for bug 563618
+ *
+ * Uses nsIConverterInputStream to decode invalid EUC-JP text
+ *
+ */
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+const test = [
+ // 0: 0x8e followed by hi byte, not valid JIS X 0201
+ [
+ "abcdefghijklmnopqrstuvwxyz12test00%8e%80foobar",
+ // expected: one replacement character, invalid byte eaten
+ "abcdefghijklmnopqrstuvwxyz12test00\uFFFDfoobar",
+ ],
+ // 1: 0x8e followed by ASCII
+ [
+ "abcdefghijklmnopqrstuvwxyz12test01%8efoobar",
+ // expected: one replacement character, invalid byte not eaten
+ "abcdefghijklmnopqrstuvwxyz12test01\uFFFDfoobar",
+ ],
+ // 2: JIS X 0208 lead byte followed by invalid hi byte
+ [
+ "abcdefghijklmnopqrstuvwxyz12test02%bf%80foobar",
+ // expected: one replacement character, invalid byte eaten
+ "abcdefghijklmnopqrstuvwxyz12test02\uFFFDfoobar",
+ ],
+ // 3: JIS X 0208 lead byte followed by ASCII
+ [
+ "abcdefghijklmnopqrstuvwxyz12test03%bffoobar",
+ // expected: one replacement character, invalid byte not eaten
+ "abcdefghijklmnopqrstuvwxyz12test03\uFFFDfoobar",
+ ],
+];
+
+const ConverterInputStream = Components.Constructor(
+ "@mozilla.org/intl/converter-input-stream;1",
+ "nsIConverterInputStream",
+ "init"
+);
+
+function testCase(testText, expectedText, bufferLength, charset) {
+ var dataURI = "data:text/plain;charset=" + charset + "," + testText;
+ var channel = NetUtil.newChannel({
+ uri: dataURI,
+ loadUsingSystemPrincipal: true,
+ });
+ var testInputStream = channel.open();
+ var testConverter = new ConverterInputStream(
+ testInputStream,
+ charset,
+ bufferLength,
+ 0xfffd
+ );
+
+ if (!(testConverter instanceof Ci.nsIUnicharLineInputStream)) {
+ throw new Error("not line input stream");
+ }
+
+ var outStr = "";
+ var more;
+ do {
+ // read the line and check for eof
+ var line = {};
+ more = testConverter.readLine(line);
+ outStr += line.value;
+ } while (more);
+
+ if (outStr != expectedText) {
+ dump("Failed with bufferLength = " + bufferLength + "\n");
+ if (outStr.length == expectedText.length) {
+ for (let i = 0; i < outStr.length; ++i) {
+ if (outStr.charCodeAt(i) != expectedText.charCodeAt(i)) {
+ dump(
+ i +
+ ": " +
+ outStr.charCodeAt(i).toString(16) +
+ " != " +
+ expectedText.charCodeAt(i).toString(16) +
+ "\n"
+ );
+ }
+ }
+ }
+ }
+
+ // escape the strings before comparing for better readability
+ Assert.equal(escape(outStr), escape(expectedText));
+}
+
+function run_test() {
+ for (var i = 0; i < test.length; ++i) {
+ for (var bufferLength = 32; bufferLength < 40; ++bufferLength) {
+ testCase(test[i][0], test[i][1], bufferLength, "EUC-JP");
+ }
+ }
+}