@electerm/ssh2 1.17.2 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -244,6 +244,8 @@ class Client extends EventEmitter {
244
244
  ? cfg.debug
245
245
  : undefined);
246
246
 
247
+ this.config.sftpEncoding = cfg.sftpEncoding || 'utf8';
248
+
247
249
  if (cfg.agentForward === true && !this.config.allowAgentFwd) {
248
250
  throw new Error(
249
251
  'You must set a valid agent path to allow agent forwarding'
@@ -604,7 +606,7 @@ class Client extends EventEmitter {
604
606
  };
605
607
  const instance = (
606
608
  isSFTP
607
- ? new SFTP(this, chanInfo, { debug })
609
+ ? new SFTP(this, chanInfo, { debug, encoding: this.config.sftpEncoding })
608
610
  : new Channel(this, chanInfo)
609
611
  );
610
612
  this._chanMgr.update(info.recipient, instance);
@@ -8,6 +8,7 @@ const {
8
8
  Writable: WritableStream
9
9
  } = require('stream');
10
10
  const { inherits, types: { isDate } } = require('util');
11
+ const iconv = require('iconv-lite');
11
12
 
12
13
  const FastBuffer = Buffer[Symbol.species];
13
14
 
@@ -147,6 +148,7 @@ class SFTP extends EventEmitter {
147
148
  this._version = -1;
148
149
  this._extensions = {};
149
150
  this._biOpt = cfg.biOpt;
151
+ this._encoding = cfg.encoding || 'utf8';
150
152
  this._pktLenBytes = 0;
151
153
  this._pktLen = 0;
152
154
  this._pktPos = 0;
@@ -2949,15 +2951,14 @@ const CLIENT_HANDLERS = {
2949
2951
  if (count !== undefined) {
2950
2952
  let names = [];
2951
2953
  for (let i = 0; i < count; ++i) {
2952
- // We are going to assume UTF-8 for filenames despite the SFTPv3
2953
- // spec not specifying an encoding because the specs for newer
2954
- // versions of the protocol all explicitly specify UTF-8 for
2955
- // filenames
2956
- const filename = bufferParser.readString(true);
2954
+ // Decode filenames using the configured encoding
2955
+ const filenameBuf = bufferParser.readString();
2956
+ const filename = (filenameBuf ? iconv.decode(filenameBuf, sftp._encoding) : '');
2957
2957
 
2958
2958
  // `longname` only exists in SFTPv3 and since it typically will
2959
- // contain the filename, we assume it is also UTF-8
2960
- const longname = bufferParser.readString(true);
2959
+ // contain the filename, we assume it uses the same encoding
2960
+ const longnameBuf = bufferParser.readString();
2961
+ const longname = (longnameBuf ? iconv.decode(longnameBuf, sftp._encoding) : '');
2961
2962
 
2962
2963
  const attrs = readAttrs(sftp._biOpt);
2963
2964
  if (attrs === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electerm/ssh2",
3
- "version": "1.17.2",
3
+ "version": "1.18.0",
4
4
  "author": "Brian White <mscdex@mscdex.net>",
5
5
  "description": "SSH2 client and server modules written in pure JavaScript for node.js",
6
6
  "main": "./lib/index.js",
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "asn1": "^0.2.6",
12
- "bcrypt-pbkdf": "^1.0.2"
12
+ "bcrypt-pbkdf": "^1.0.2",
13
+ "iconv-lite": "^0.7.2"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@mscdex/eslint-config": "^1.1.0",