Skip to content

Commit

Permalink
Fix Python3.13 compatibility regarding urllib.parse module
Browse files Browse the repository at this point in the history
Python 3.13 fixed handling relative paths in urllib.parse module.
Specifically, relative file URL is now constructed as file:path instead
of converting it to absolute file:///path. This breaks
salt.utils.url.create which expects file:/// specifically. The mismatch
results in for example changing salt://top.sls into salt://.sls and thus
not finding the top file.

Fix this by handling both prefixes.

Relevant python change: python/cpython#85110
Fixes: saltstack#66898
  • Loading branch information
marmarek committed Oct 7, 2024
1 parent 58c89a8 commit 759c030
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/66898.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed Python 3.13 compatibility regarding urllib.parse module
2 changes: 1 addition & 1 deletion salt/utils/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create(path, saltenv=None):

query = f"saltenv={saltenv}" if saltenv else ""
url = salt.utils.data.decode(urlunparse(("file", "", path, "", query, "")))
return "salt://{}".format(url[len("file:///") :])
return f'salt://{re.sub(r"^file:/*", "", url)}'


def is_escaped(url):
Expand Down

0 comments on commit 759c030

Please sign in to comment.