realtymaps / promise-sftp

a promise-based sftp client for node.js
MIT License
16 stars 11 forks source link

Functions added to Object.prototype cause error "Unrecognized finishType:" #17

Open urbinopescada opened 3 years ago

urbinopescada commented 3 years ago

Hello,

First, thank you for the great module :)

There is an issue when some functions or properties are added to the Object prototype by some other library. It will cause finishType to have unexpected values. I was able to track it down to promise-sftp/lib/promiseSftp.coffee line 443:

    # create the methods listed in simplePassthroughMethods as common logic wrapped around the original sshClient method
    for name,finishType of simplePassthroughMethods
      @[name] = commonLogicFactory(name, finishType)

    # wrap the methods listed in complexPassthroughMethods with common logic
    for name,finishType of complexPassthroughMethods
      @[name] = commonLogicFactory(name, finishType, @[name])

It is being distributed in javascript as:

      for (name in simplePassthroughMethods) {
        finishType = simplePassthroughMethods[name];
        this[name] = commonLogicFactory(name, finishType);
      }
      for (name in complexPassthroughMethods) {
        finishType = complexPassthroughMethods[name];
        this[name] = commonLogicFactory(name, finishType, this[name]);
      }

The issue would be solved by using Object.keys() instead of for...in, for example.

Do you think this can be fixed?

Thank you very much, Urbino Pescada