diff --git a/airflow/providers/samba/hooks/samba.py b/airflow/providers/samba/hooks/samba.py index 7f846e351b10c..df46c0cf3489a 100644 --- a/airflow/providers/samba/hooks/samba.py +++ b/airflow/providers/samba/hooks/samba.py @@ -80,7 +80,7 @@ def __exit__(self, exc_type, exc_value, traceback): self._connection_cache.clear() def _join_path(self, path): - return f"//{posixpath.join(self._host, self._share, path)}" + return f"//{posixpath.join(self._host, self._share, path.lstrip('/'))}" @wraps(smbclient.link) def link(self, src, dst, follow_symlinks=True): diff --git a/tests/providers/samba/hooks/test_samba.py b/tests/providers/samba/hooks/test_samba.py index 4fb36d8ca9f94..a2c45a829c973 100644 --- a/tests/providers/samba/hooks/test_samba.py +++ b/tests/providers/samba/hooks/test_samba.py @@ -130,3 +130,15 @@ def test_method(self, name, get_conn_mock): # We expect keyword arguments to include the connection settings. assert dict(kwargs, **connection_settings) == p_kwargs + + @parameterized.expand( + [ + ("/start/path/with/slash", "//ip/share/start/path/with/slash"), + ("start/path/without/slash", "//ip/share/start/path/without/slash"), + ], + ) + @mock.patch('airflow.hooks.base.BaseHook.get_connection') + def test__join_path(self, path, full_path, get_conn_mock): + get_conn_mock.return_value = CONNECTION + hook = SambaHook('samba_default') + assert hook._join_path(path) == full_path