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

[3006.x] file.managed correctly handles file path with '#' #66302

Merged
merged 5 commits into from
Apr 8, 2024
Merged
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
1 change: 1 addition & 0 deletions changelog/63060.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file.managed correctly handles file path with '#'
2 changes: 1 addition & 1 deletion salt/fileclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def get_url(
"""
Get a single file from a URL.
"""
url_data = urllib.parse.urlparse(url)
url_data = urllib.parse.urlparse(url, allow_fragments=False)
url_scheme = url_data.scheme
url_path = os.path.join(url_data.netloc, url_data.path).rstrip(os.sep)

Expand Down
16 changes: 16 additions & 0 deletions tests/pytests/unit/fileclient/test_fileclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,19 @@ 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"
Loading