Skip to content

Commit efa52f0

Browse files
authored
fix unstrip_protocol when no default port set (#105)
1 parent 34b618d commit efa52f0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

dvc_ssh/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ def _strip_protocol(cls, path: str) -> str:
4141

4242
def unstrip_protocol(self, path: str) -> str:
4343
host = self.fs_args["host"]
44-
port = self.fs_args["port"]
44+
port = self.fs_args.get("port")
4545
path = path.lstrip("/")
46-
return f"ssh://{host}:{port}/{path}"
46+
47+
url = f"ssh://{host}"
48+
if port:
49+
url += f":{port}"
50+
url += f"/{path}"
51+
return url
4752

4853
def _prepare_credentials(self, **config):
4954
from .client import InteractiveSSHClient

dvc_ssh/tests/test_fs.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,17 @@ def test_ssh_keyfile(config, expected_keyfile):
103103
def test_ssh_gss_auth(config, expected_gss_auth):
104104
fs = SSHFileSystem(**config)
105105
assert fs.fs_args["gss_auth"] == expected_gss_auth
106+
107+
108+
@pytest.mark.parametrize(
109+
"config,path,expected_path",
110+
[
111+
({"host": "example.com"}, "path", "ssh://example.com/path"),
112+
({"host": "example.com"}, "/path", "ssh://example.com/path"),
113+
({"host": "example.com", "port": 1234}, "path", "ssh://example.com:1234/path"),
114+
({"host": "example.com", "port": 1234}, "/path", "ssh://example.com:1234/path"),
115+
],
116+
)
117+
def test_unstrip_protocol(mocker, config, path, expected_path):
118+
fs = SSHFileSystem(**config, fs=mocker.MagicMock())
119+
assert fs.unstrip_protocol(path) == expected_path

0 commit comments

Comments
 (0)