diff options
Diffstat (limited to 'test')
23 files changed, 142 insertions, 51 deletions
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js index 867aedf0f6..ebf6a01a0a 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js @@ -29,5 +29,5 @@ if (!binding.ensureAllocation(2 * kStringMaxLength)) { return; } -const maxString = buf.toString('binary'); +const maxString = buf.toString('latin1'); assert.equal(maxString.length, kStringMaxLength); diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js index 04e4ad9f93..0fa4bca723 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js @@ -30,13 +30,13 @@ if (!binding.ensureAllocation(2 * kStringMaxLength)) { } assert.throws(function() { - buf.toString('binary'); + buf.toString('latin1'); }, /"toString\(\)" failed/); -var maxString = buf.toString('binary', 1); +var maxString = buf.toString('latin1', 1); assert.equal(maxString.length, kStringMaxLength); // Free the memory early instead of at the end of the next assignment maxString = undefined; -maxString = buf.toString('binary', 0, kStringMaxLength); +maxString = buf.toString('latin1', 0, kStringMaxLength); assert.equal(maxString.length, kStringMaxLength); diff --git a/test/disabled/tls_server.js b/test/disabled/tls_server.js index 14e48f6b31..1e72809a8a 100644 --- a/test/disabled/tls_server.js +++ b/test/disabled/tls_server.js @@ -19,7 +19,7 @@ try { var i = 0; var server = net.createServer(function(connection) { connection.setSecure(credentials); - connection.setEncoding('binary'); + connection.setEncoding('latin1'); connection.on('secure', function() { //console.log('Secure'); diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 0f06393d6a..83e9e2f510 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -235,7 +235,7 @@ assert.strictEqual('Unknown encoding: invalid', caught_error.message); // try to create 0-length buffers Buffer.from(''); Buffer.from('', 'ascii'); -Buffer.from('', 'binary'); +Buffer.from('', 'latin1'); Buffer.alloc(0); Buffer.allocUnsafe(0); @@ -689,7 +689,7 @@ assert.equal(dot.toString('base64'), '//4uAA=='); for (let i = 0; i < segments.length; ++i) { pos += b.write(segments[i], pos, 'base64'); } - assert.equal(b.toString('binary', 0, pos), 'Madness?! This is node.js!'); + assert.equal(b.toString('latin1', 0, pos), 'Madness?! This is node.js!'); } // Regression test for https://github.com/nodejs/node/issues/3496. @@ -845,13 +845,13 @@ assert.equal(0, Buffer.from('hello').slice(0, 0).length); // Binary encoding should write only one byte per character. const b = Buffer.from([0xde, 0xad, 0xbe, 0xef]); let s = String.fromCharCode(0xffff); - b.write(s, 0, 'binary'); + b.write(s, 0, 'latin1'); assert.equal(0xff, b[0]); assert.equal(0xad, b[1]); assert.equal(0xbe, b[2]); assert.equal(0xef, b[3]); s = String.fromCharCode(0xaaee); - b.write(s, 0, 'binary'); + b.write(s, 0, 'latin1'); assert.equal(0xee, b[0]); assert.equal(0xad, b[1]); assert.equal(0xbe, b[2]); @@ -969,7 +969,7 @@ assert.equal(0, Buffer.from('hello').slice(0, 0).length); // test for buffer overrun const buf = Buffer.from([0, 0, 0, 0, 0]); // length: 5 var sub = buf.slice(0, 4); // length: 4 - written = sub.write('12345', 'binary'); + written = sub.write('12345', 'latin1'); assert.equal(written, 4); assert.equal(buf[4], 0); } @@ -992,7 +992,7 @@ assert.equal(Buffer.from('99').length, 2); assert.equal(Buffer.from('13.37').length, 5); // Ensure that the length argument is respected. -'ascii utf8 hex base64 binary'.split(' ').forEach(function(enc) { +'ascii utf8 hex base64 latin1'.split(' ').forEach(function(enc) { assert.equal(Buffer.allocUnsafe(1).write('aaaaaa', 0, 1, enc), 1); }); @@ -1011,6 +1011,7 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0); 'utf8', 'utf-8', 'ascii', + 'latin1', 'binary', 'base64', 'ucs2', diff --git a/test/parallel/test-buffer-bytelength.js b/test/parallel/test-buffer-bytelength.js index 01bf12e544..97e24193c1 100644 --- a/test/parallel/test-buffer-bytelength.js +++ b/test/parallel/test-buffer-bytelength.js @@ -6,9 +6,9 @@ var Buffer = require('buffer').Buffer; var SlowBuffer = require('buffer').SlowBuffer; // coerce values to string -assert.equal(Buffer.byteLength(32, 'binary'), 2); +assert.equal(Buffer.byteLength(32, 'latin1'), 2); assert.equal(Buffer.byteLength(NaN, 'utf8'), 3); -assert.equal(Buffer.byteLength({}, 'binary'), 15); +assert.equal(Buffer.byteLength({}, 'latin1'), 15); assert.equal(Buffer.byteLength(), 9); var buff = new Buffer(10); @@ -80,6 +80,7 @@ assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3); assert.equal(Buffer.byteLength('Il était tué'), 14); assert.equal(Buffer.byteLength('Il était tué', 'utf8'), 14); assert.equal(Buffer.byteLength('Il était tué', 'ascii'), 12); +assert.equal(Buffer.byteLength('Il était tué', 'latin1'), 12); assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12); ['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { assert.equal(24, Buffer.byteLength('Il était tué', encoding)); diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 667cede052..638fda819d 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -73,6 +73,27 @@ testBufs('a\u0234b\u0235c\u0236', 4, 1, 'binary'); testBufs('a\u0234b\u0235c\u0236', 12, 1, 'binary'); +// LATIN1 +testBufs('abc', 'latin1'); +testBufs('\u0222aa', 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 'latin1'); +testBufs('abc', 4, 'latin1'); +testBufs('abc', 5, 'latin1'); +testBufs('abc', SIZE, 'latin1'); +testBufs('\u0222aa', 2, 'latin1'); +testBufs('\u0222aa', 8, 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 4, 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 12, 'latin1'); +testBufs('abc', 4, -1, 'latin1'); +testBufs('abc', 4, 1, 'latin1'); +testBufs('abc', 5, 1, 'latin1'); +testBufs('\u0222aa', 2, -1, 'latin1'); +testBufs('\u0222aa', 8, 1, 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 4, -1, 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 4, 1, 'latin1'); +testBufs('a\u0234b\u0235c\u0236', 12, 1, 'latin1'); + + // UCS2 testBufs('abc', 'ucs2'); testBufs('\u0222aa', 'ucs2'); diff --git a/test/parallel/test-buffer-includes.js b/test/parallel/test-buffer-includes.js index 7962d1cef8..90f24c01f3 100644 --- a/test/parallel/test-buffer-includes.js +++ b/test/parallel/test-buffer-includes.js @@ -102,6 +102,14 @@ assert( Buffer.from(b.toString('ascii'), 'ascii') .includes(Buffer.from('d', 'ascii'), 0, 'ascii')); +// test latin1 encoding +assert( + Buffer.from(b.toString('latin1'), 'latin1') + .includes('d', 0, 'latin1')); +assert( + Buffer.from(b.toString('latin1'), 'latin1') + .includes(Buffer.from('d', 'latin1'), 0, 'latin1')); + // test binary encoding assert( Buffer.from(b.toString('binary'), 'binary') diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 647f1e9a62..3d5620aa81 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -102,6 +102,23 @@ assert.equal( Buffer.from(b.toString('ascii'), 'ascii') .indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), 3); +// test latin1 encoding +assert.equal( + Buffer.from(b.toString('latin1'), 'latin1') + .indexOf('d', 0, 'latin1'), 3); +assert.equal( + Buffer.from(b.toString('latin1'), 'latin1') + .indexOf(Buffer.from('d', 'latin1'), 0, 'latin1'), 3); +assert.equal( + Buffer.from('aa\u00e8aa', 'latin1') + .indexOf('\u00e8', 'latin1'), 2); +assert.equal( + Buffer.from('\u00e8', 'latin1') + .indexOf('\u00e8', 'latin1'), 0); +assert.equal( + Buffer.from('\u00e8', 'latin1') + .indexOf(Buffer.from('\u00e8', 'latin1'), 'latin1'), 0); + // test binary encoding assert.equal( Buffer.from(b.toString('binary'), 'binary') @@ -357,20 +374,24 @@ assert.equal(b.lastIndexOf('b', [2]), 1); // Test needles longer than the haystack. assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'ucs2'), -1); assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'utf8'), -1); +assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'latin1'), -1); assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'binary'), -1); assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa')), -1); assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 2, 'ucs2'), -1); assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 3, 'utf8'), -1); +assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'latin1'), -1); assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'binary'), -1); assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa'), 7), -1); // 你好 expands to a total of 6 bytes using UTF-8 and 4 bytes using UTF-16 assert.strictEqual(buf_bc.lastIndexOf('你好', 'ucs2'), -1); assert.strictEqual(buf_bc.lastIndexOf('你好', 'utf8'), -1); +assert.strictEqual(buf_bc.lastIndexOf('你好', 'latin1'), -1); assert.strictEqual(buf_bc.lastIndexOf('你好', 'binary'), -1); assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好')), -1); assert.strictEqual(buf_bc.lastIndexOf('你好', 2, 'ucs2'), -1); assert.strictEqual(buf_bc.lastIndexOf('你好', 3, 'utf8'), -1); +assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'latin1'), -1); assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1); assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1); @@ -395,6 +416,7 @@ assert.equal(-1, bufferString.lastIndexOf('a ', -28)); // but in a part of the buffer that does not make search to search // due do length constraints. const abInUCS2 = Buffer.from('ab', 'ucs2'); +assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'latin1').lastIndexOf('µ')); assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'binary').lastIndexOf('µ')); assert.strictEqual(-1, Buffer.from('bc').lastIndexOf('ab')); assert.strictEqual(-1, Buffer.from('abc').lastIndexOf('qa')); diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index f773da321d..f3ab74902b 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -237,6 +237,7 @@ assert.strictEqual('Unknown encoding: invalid', caught_error.message); // try to create 0-length buffers new Buffer(''); new Buffer('', 'ascii'); +new Buffer('', 'latin1'); new Buffer('', 'binary'); Buffer(0); @@ -687,6 +688,7 @@ assert.equal(dot.toString('base64'), '//4uAA=='); for (let i = 0; i < segments.length; ++i) { pos += b.write(segments[i], pos, 'base64'); } + assert.equal(b.toString('latin1', 0, pos), 'Madness?! This is node.js!'); assert.equal(b.toString('binary', 0, pos), 'Madness?! This is node.js!'); } @@ -846,6 +848,23 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); }); { + // latin1 encoding should write only one byte per character. + const b = Buffer([0xde, 0xad, 0xbe, 0xef]); + let s = String.fromCharCode(0xffff); + b.write(s, 0, 'latin1'); + assert.equal(0xff, b[0]); + assert.equal(0xad, b[1]); + assert.equal(0xbe, b[2]); + assert.equal(0xef, b[3]); + s = String.fromCharCode(0xaaee); + b.write(s, 0, 'latin1'); + assert.equal(0xee, b[0]); + assert.equal(0xad, b[1]); + assert.equal(0xbe, b[2]); + assert.equal(0xef, b[3]); +} + +{ // Binary encoding should write only one byte per character. const b = Buffer([0xde, 0xad, 0xbe, 0xef]); let s = String.fromCharCode(0xffff); @@ -973,6 +992,9 @@ assert.equal(0, Buffer('hello').slice(0, 0).length); // test for buffer overrun const buf = new Buffer([0, 0, 0, 0, 0]); // length: 5 var sub = buf.slice(0, 4); // length: 4 + written = sub.write('12345', 'latin1'); + assert.equal(written, 4); + assert.equal(buf[4], 0); written = sub.write('12345', 'binary'); assert.equal(written, 4); assert.equal(buf[4], 0); @@ -994,7 +1016,7 @@ assert.equal(Buffer('99').length, 2); assert.equal(Buffer('13.37').length, 5); // Ensure that the length argument is respected. -'ascii utf8 hex base64 binary'.split(' ').forEach(function(enc) { +'ascii utf8 hex base64 latin1 binary'.split(' ').forEach(function(enc) { assert.equal(Buffer(1).write('aaaaaa', 0, 1, enc), 1); }); @@ -1013,6 +1035,7 @@ Buffer(Buffer(0), 0, 0); 'utf8', 'utf-8', 'ascii', + 'latin1', 'binary', 'base64', 'ucs2', diff --git a/test/parallel/test-crypto-binary-default.js b/test/parallel/test-crypto-binary-default.js index 74447ce69d..bca8e13dd5 100644 --- a/test/parallel/test-crypto-binary-default.js +++ b/test/parallel/test-crypto-binary-default.js @@ -14,7 +14,7 @@ var crypto = require('crypto'); var tls = require('tls'); const DH_NOT_SUITABLE_GENERATOR = crypto.constants.DH_NOT_SUITABLE_GENERATOR; -crypto.DEFAULT_ENCODING = 'binary'; +crypto.DEFAULT_ENCODING = 'latin1'; var fs = require('fs'); var path = require('path'); @@ -346,11 +346,11 @@ var a3 = crypto.createHash('sha512').update('Test123').digest(); // binary var a4 = crypto.createHash('sha1').update('Test123').digest('buffer'); if (!common.hasFipsCrypto) { - var a0 = crypto.createHash('md5').update('Test123').digest('binary'); + var a0 = crypto.createHash('md5').update('Test123').digest('latin1'); assert.equal( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', - 'Test MD5 as binary' + 'Test MD5 as latin1' ); } @@ -364,7 +364,7 @@ assert.equal(a3, '\u00c1(4\u00f1\u0003\u001fd\u0097!O\'\u00d4C/&Qz\u00d4' + '\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' + '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', - 'Test SHA512 as assumed binary'); + 'Test SHA512 as assumed latin1'); assert.deepStrictEqual( a4, @@ -530,7 +530,7 @@ var dh2 = crypto.createDiffieHellman(p1, 'base64'); var key1 = dh1.generateKeys(); var key2 = dh2.generateKeys('hex'); var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'binary', 'buffer'); +var secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); assert.equal(secret1, secret2.toString('base64')); diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index e9fbd30a2e..9d383ed417 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -17,7 +17,7 @@ var dh2 = crypto.createDiffieHellman(p1, 'buffer'); var key1 = dh1.generateKeys(); var key2 = dh2.generateKeys('hex'); var secret1 = dh1.computeSecret(key2, 'hex', 'base64'); -var secret2 = dh2.computeSecret(key1, 'binary', 'buffer'); +var secret2 = dh2.computeSecret(key1, 'latin1', 'buffer'); assert.equal(secret1, secret2.toString('base64')); assert.equal(dh1.verifyError, 0); @@ -155,7 +155,7 @@ const ecdh2 = crypto.createECDH('prime256v1'); key1 = ecdh1.generateKeys(); key2 = ecdh2.generateKeys('hex'); secret1 = ecdh1.computeSecret(key2, 'hex', 'base64'); -secret2 = ecdh2.computeSecret(key1, 'binary', 'buffer'); +secret2 = ecdh2.computeSecret(key1, 'latin1', 'buffer'); assert.equal(secret1, secret2.toString('base64')); @@ -176,7 +176,7 @@ const ecdh3 = crypto.createECDH('secp256k1'); const key3 = ecdh3.generateKeys(); assert.throws(function() { - ecdh2.computeSecret(key3, 'binary', 'buffer'); + ecdh2.computeSecret(key3, 'latin1', 'buffer'); }); // ECDH should allow .setPrivateKey()/.setPublicKey() diff --git a/test/parallel/test-crypto-hash.js b/test/parallel/test-crypto-hash.js index 55817ea69c..81ee1d60c5 100644 --- a/test/parallel/test-crypto-hash.js +++ b/test/parallel/test-crypto-hash.js @@ -38,11 +38,11 @@ a8.end(); a8 = a8.read(); if (!common.hasFipsCrypto) { - var a0 = crypto.createHash('md5').update('Test123').digest('binary'); + var a0 = crypto.createHash('md5').update('Test123').digest('latin1'); assert.equal( a0, 'h\u00ea\u00cb\u0097\u00d8o\fF!\u00fa+\u000e\u0017\u00ca\u00bd\u008c', - 'Test MD5 as binary' + 'Test MD5 as latin1' ); } assert.equal(a1, '8308651804facb7b9af8ffc53a33a22d6a1c8ac2', 'Test SHA1'); @@ -56,7 +56,7 @@ assert.deepStrictEqual( '\u00d6\u0092\u00a3\u00df\u00a2i\u00a1\u009b\n\n*\u000f' + '\u00d7\u00d6\u00a2\u00a8\u0085\u00e3<\u0083\u009c\u0093' + '\u00c2\u0006\u00da0\u00a1\u00879(G\u00ed\'', - 'binary'), + 'latin1'), 'Test SHA512 as assumed buffer'); assert.deepStrictEqual( a4, @@ -102,7 +102,7 @@ assert.equal( assert.notEqual( hutf8, - crypto.createHash('sha512').update('УТФ-8 text', 'binary').digest('hex')); + crypto.createHash('sha512').update('УТФ-8 text', 'latin1').digest('hex')); var h3 = crypto.createHash('sha256'); h3.digest(); diff --git a/test/parallel/test-crypto-padding-aes256.js b/test/parallel/test-crypto-padding-aes256.js index be1edd5edb..e835867d61 100644 --- a/test/parallel/test-crypto-padding-aes256.js +++ b/test/parallel/test-crypto-padding-aes256.js @@ -18,13 +18,13 @@ function aes256(decipherFinal) { function encrypt(val, pad) { var c = crypto.createCipheriv('aes256', key, iv); c.setAutoPadding(pad); - return c.update(val, 'utf8', 'binary') + c.final('binary'); + return c.update(val, 'utf8', 'latin1') + c.final('latin1'); } function decrypt(val, pad) { var c = crypto.createDecipheriv('aes256', key, iv); c.setAutoPadding(pad); - return c.update(val, 'binary', 'utf8') + c[decipherFinal]('utf8'); + return c.update(val, 'latin1', 'utf8') + c[decipherFinal]('utf8'); } // echo 0123456789abcdef0123456789abcdef \ diff --git a/test/parallel/test-crypto-padding.js b/test/parallel/test-crypto-padding.js index a617472873..7822df64d9 100644 --- a/test/parallel/test-crypto-padding.js +++ b/test/parallel/test-crypto-padding.js @@ -65,7 +65,7 @@ function dec(encd, pad) { var decrypt = crypto.createDecipheriv(CIPHER_NAME, KEY_PLAIN, IV_PLAIN); decrypt.setAutoPadding(pad); var plain = decrypt.update(encd, 'hex'); - plain += decrypt.final('binary'); + plain += decrypt.final('latin1'); return plain; } diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index ea888180a0..c1897c2d69 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -13,10 +13,10 @@ var crypto = require('crypto'); // function testPBKDF2(password, salt, iterations, keylen, expected) { var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen, 'sha256'); - assert.equal(actual.toString('binary'), expected); + assert.equal(actual.toString('latin1'), expected); crypto.pbkdf2(password, salt, iterations, keylen, 'sha256', (err, actual) => { - assert.equal(actual.toString('binary'), expected); + assert.equal(actual.toString('latin1'), expected); }); } diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index e8d892a8d6..77ecda3053 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -33,23 +33,23 @@ var keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); { const s2 = crypto.createSign('RSA-SHA256') .update('Test123') - .sign(keyPem, 'binary'); + .sign(keyPem, 'latin1'); let s2stream = crypto.createSign('RSA-SHA256'); s2stream.end('Test123'); - s2stream = s2stream.sign(keyPem, 'binary'); + s2stream = s2stream.sign(keyPem, 'latin1'); assert.equal(s2, s2stream, 'Stream produces same output'); let verified = crypto.createVerify('RSA-SHA256') .update('Test') .update('123') - .verify(certPem, s2, 'binary'); - assert.strictEqual(verified, true, 'sign and verify (binary)'); + .verify(certPem, s2, 'latin1'); + assert.strictEqual(verified, true, 'sign and verify (latin1)'); const verStream = crypto.createVerify('RSA-SHA256'); verStream.write('Tes'); verStream.write('t12'); verStream.end('3'); - verified = verStream.verify(certPem, s2, 'binary'); + verified = verStream.verify(certPem, s2, 'latin1'); assert.strictEqual(verified, true, 'sign and verify (stream)'); } diff --git a/test/parallel/test-file-read-noexist.js b/test/parallel/test-file-read-noexist.js index 096af7cce3..3673b701b5 100644 --- a/test/parallel/test-file-read-noexist.js +++ b/test/parallel/test-file-read-noexist.js @@ -6,7 +6,7 @@ var fs = require('fs'); var got_error = false; var filename = path.join(common.fixturesDir, 'does_not_exist.txt'); -fs.readFile(filename, 'binary', function(err, content) { +fs.readFile(filename, 'latin1', function(err, content) { if (err) { got_error = true; } else { diff --git a/test/parallel/test-fs-write-stream-encoding.js b/test/parallel/test-fs-write-stream-encoding.js index 7bbffec1a5..3ce47b7382 100644 --- a/test/parallel/test-fs-write-stream-encoding.js +++ b/test/parallel/test-fs-write-stream-encoding.js @@ -5,7 +5,7 @@ const fs = require('fs'); const path = require('path'); const stream = require('stream'); const firstEncoding = 'base64'; -const secondEncoding = 'binary'; +const secondEncoding = 'latin1'; const examplePath = path.join(common.fixturesDir, 'x.txt'); const dummyPath = path.join(common.tmpDir, 'x.txt'); diff --git a/test/parallel/test-http-status-message.js b/test/parallel/test-http-status-message.js index e579b8e995..a95ada58ba 100644 --- a/test/parallel/test-http-status-message.js +++ b/test/parallel/test-http-status-message.js @@ -22,7 +22,7 @@ function test() { bufs.push(chunk); }); client.on('end', function() { - var head = Buffer.concat(bufs).toString('binary').split('\r\n')[0]; + var head = Buffer.concat(bufs).toString('latin1').split('\r\n')[0]; assert.equal('HTTP/1.1 200 Custom Message', head); console.log('ok'); s.close(); diff --git a/test/parallel/test-net-binary.js b/test/parallel/test-net-binary.js index 484ae60c11..48f8c04194 100644 --- a/test/parallel/test-net-binary.js +++ b/test/parallel/test-net-binary.js @@ -14,9 +14,9 @@ for (var i = 255; i >= 0; i--) { // safe constructor var echoServer = net.Server(function(connection) { - connection.setEncoding('binary'); + connection.setEncoding('latin1'); connection.on('data', function(chunk) { - connection.write(chunk, 'binary'); + connection.write(chunk, 'latin1'); }); connection.on('end', function() { connection.end(); @@ -32,11 +32,11 @@ echoServer.on('listening', function() { port: common.PORT }); - c.setEncoding('binary'); + c.setEncoding('latin1'); c.on('data', function(chunk) { var n = j + chunk.length; while (j < n && j < 256) { - c.write(String.fromCharCode(j), 'binary'); + c.write(String.fromCharCode(j), 'latin1'); j++; } if (j === 256) { diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 879684007c..92479fc88f 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -58,7 +58,7 @@ function test(decode, uncork, multi, next) { { encoding: 'ascii', chunk: 'hello, ' }, { encoding: 'utf8', chunk: 'world' }, { encoding: 'buffer', chunk: [33] }, - { encoding: 'binary', chunk: '\nand then...' }, + { encoding: 'latin1', chunk: '\nand then...' }, { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' } ]; @@ -82,7 +82,7 @@ function test(decode, uncork, multi, next) { w.cork(); w.write(Buffer.from('!'), 'buffer', cnt('!')); - w.write('\nand then...', 'binary', cnt('and then')); + w.write('\nand then...', 'latin1', cnt('and then')); if (multi) w.uncork(); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 2b687e0a24..6acfcde4ef 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -140,6 +140,7 @@ test('write bufferize', function(t) { 'utf8', 'utf-8', 'ascii', + 'latin1', 'binary', 'base64', 'ucs2', @@ -177,6 +178,7 @@ test('write no bufferize', function(t) { 'utf8', 'utf-8', 'ascii', + 'latin1', 'binary', 'base64', 'ucs2', @@ -275,7 +277,7 @@ test('encoding should be ignored for buffers', function(t) { t.end(); }; var buf = Buffer.from(hex, 'hex'); - tw.write(buf, 'binary'); + tw.write(buf, 'latin1'); }); test('writables are not pipable', function(t) { diff --git a/test/parallel/test-stringbytes-external.js b/test/parallel/test-stringbytes-external.js index 6833223217..ec7ae5aa75 100644 --- a/test/parallel/test-stringbytes-external.js +++ b/test/parallel/test-stringbytes-external.js @@ -11,7 +11,13 @@ var write_str = 'a'; // first do basic checks var b = Buffer.from(write_str, 'ucs2'); -var c = b.toString('binary'); +// first check latin1 +var c = b.toString('latin1'); +assert.equal(b[0], 0x61); +assert.equal(b[1], 0); +assert.equal(ucs2_control, c); +// now check binary +c = b.toString('binary'); assert.equal(b[0], 0x61); assert.equal(b[1], 0); assert.equal(ucs2_control, c); @@ -28,13 +34,20 @@ for (let i = 0; i < b.length; i += 2) { assert.equal(b[i], 0x61); assert.equal(b[i + 1], 0); } + // create another string to create an external string -var b_bin = b.toString('binary'); var b_ucs = b.toString('ucs2'); + +// check control against external binary string +var l_bin = b.toString('latin1'); +assert.equal(ucs2_control, l_bin); + // check control against external binary string +var b_bin = b.toString('binary'); assert.equal(ucs2_control, b_bin); + // create buffer copy from external -var c_bin = Buffer.from(b_bin, 'binary'); +var c_bin = Buffer.from(l_bin, 'latin1'); var c_ucs = Buffer.from(b_ucs, 'ucs2'); // make sure they're the same length assert.equal(c_bin.length, c_ucs.length); @@ -44,8 +57,8 @@ for (let i = 0; i < c_bin.length; i++) { } // check resultant strings assert.equal(c_bin.toString('ucs2'), c_ucs.toString('ucs2')); -assert.equal(c_bin.toString('binary'), ucs2_control); -assert.equal(c_ucs.toString('binary'), ucs2_control); +assert.equal(c_bin.toString('latin1'), ucs2_control); +assert.equal(c_ucs.toString('latin1'), ucs2_control); // now let's test BASE64 and HEX ecoding/decoding |