Paramiko raises an exception if self._cwd is a unicode object
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
paramiko |
Fix Committed
|
Medium
|
Robey Pointer |
Bug Description
If a user calls chdir(path) on a SFTP client object (where path contains special characters) and then attempts to transfer files relative to the current directory, Paramiko will be unable to upload files when given a relative destination. The exception Paramiko outputs is:
Exception: unknown type for u'/Users/
I looked at the code in sftp_client.py and it seems the function _adjust_cwd is the problem. It does ensure that the "path" argument is not a unicode object and encodes "path" if it is, however it does not perform this same check on self._cwd. When calling chdir(path), normalize(path) is used to set self._cwd. Since normalize returns a Unicode object, if "path" is not an absolute path and the current directory contains special characters, then Paramiko fails with the exception above.
I've attached a patch which changes the behavior of _adjust_cwd so that instead of returning the new paths immediately, the new paths are assigned to a temporary final_path variable. The unicode check is performed last to ensure that final_path is not a Unicode object.
Changed in paramiko: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
assignee: | nobody → Robey Pointer (robey) |
milestone: | none → 1.7.6 |
Changed in paramiko: | |
status: | Confirmed → Fix Committed |
it sounds like the real problem is normalize returning a unicode object, so if i make chdir turn the path into utf-8, that should also fix it.