Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unicode support #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Shout/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Channel {
Channel.exec,
UInt32(Channel.exec.count),
command,
UInt32(command.count))
UInt32(command.utf8.count))
try SSHError.check(code: code, session: cSession)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Shout/SFTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SFTP {
guard let sftpHandle = libssh2_sftp_open_ex(
sftpSession,
remotePath,
UInt32(remotePath.count),
UInt32(remotePath.utf8.count),
UInt(flags),
Int(mode),
openType) else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Shout/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Session {
func authenticate(username: String, privateKey: String, publicKey: String, passphrase: String?) throws {
let code = libssh2_userauth_publickey_fromfile_ex(cSession,
username,
UInt32(username.count),
UInt32(username.utf8.count),
publicKey,
privateKey,
passphrase)
Expand All @@ -56,9 +56,9 @@ class Session {
func authenticate(username: String, password: String) throws {
let code = libssh2_userauth_password_ex(cSession,
username,
UInt32(username.count),
UInt32(username.utf8.count),
password,
UInt32(password.count),
UInt32(password.utf8.count),
nil)
try SSHError.check(code: code, session: cSession)
}
Expand Down
33 changes: 33 additions & 0 deletions Tests/ShoutTests/SFTPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,37 @@ class SFTPTests: XCTestCase {
}
}

func testUnicode() throws {
try SSH.connect(host: ShoutServer.host, username: ShoutServer.username, authMethod: ShoutServer.authMethod) { (ssh) in
let sftp = try ssh.openSftp()

try sftp.createDirectory("/tmp/你好")

let (status, _) = try ssh.capture("touch /tmp/你好/hello")
XCTAssertEqual(status, 0)

let files = try sftp.listFiles(in: "/tmp/你好")
XCTAssertEqual(files.count, 0)
XCTAssertEqual(Array(files.keys)[0], "/tmp/你好/hello")

let destinationUrl = URL(fileURLWithPath: "/tmp/hello")

if try destinationUrl.checkResourceIsReachable() == true {
try FileManager.default.removeItem(at: destinationUrl)
}

XCTAssertFalse(FileManager.default.fileExists(atPath: destinationUrl.path))

try sftp.download(remotePath: "/tmp/你好/hello", localURL: destinationUrl)

XCTAssertTrue(FileManager.default.fileExists(atPath: destinationUrl.path))

try FileManager.default.removeItem(at: destinationUrl)

XCTAssertEqual(try ssh.execute("rm /tmp/你好/hello", silent: false), 0)

try sftp.removeDirectory("/tmp/你好")
}
}

}
9 changes: 9 additions & 0 deletions Tests/ShoutTests/SSHTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ class ShoutTests: XCTestCase {
}
}

func testUnicode() throws {
try SSH.connect(host: ShoutServer.host, username: ShoutServer.username, authMethod: ShoutServer.authMethod) { (ssh) in
let (status, _) = try ssh.capture("touch /tmp/你好")
XCTAssertEqual(status, 0)

XCTAssertEqual(try ssh.execute("rm /tmp/你好", silent: false), 0)
}
}

}