file.managed correctly handles paths containing a '#'

This commit is contained in:
Tyler Levy Conde 2024-04-02 15:57:58 -06:00 committed by Pedro Algarvio
parent 653b61a2c9
commit a649fec423
2 changed files with 16 additions and 0 deletions

View file

@ -481,9 +481,11 @@ class Client:
"""
Get a single file from a URL.
"""
url = urllib.parse.quote(url, safe=":/")
url_data = urllib.parse.urlparse(url)
url_scheme = url_data.scheme
url_path = os.path.join(url_data.netloc, url_data.path).rstrip(os.sep)
url_path = urllib.parse.unquote(url_path)
# If dest is a directory, rewrite dest with filename
if dest is not None and (os.path.isdir(dest) or dest.endswith(("/", "\\"))):

View file

@ -223,3 +223,17 @@ def test_get_file_client(file_client):
with patch("salt.fileclient.RemoteClient", MagicMock(return_value="remote_client")):
ret = fileclient.get_file_client(minion_opts)
assert "remote_client" == ret
def test_get_url_with_hash(client_opts):
"""
Test get_url function with a URL containing a hash character.
"""
with patch("os.path.isfile", return_value=True):
with patch("os.makedirs", return_value=None):
with patch("urllib.request.urlretrieve", return_value=None):
client = fileclient.Client(client_opts)
url = "file:///path/to/file#with#hash"
dest = "/mocked/destination"
result = client.get_url(url, dest)
assert result == "/path/to/file#with#hash"