Skip to content

Commit

Permalink
fix(auth): ensures / is URL encoded in sources auth environment var…
Browse files Browse the repository at this point in the history
…iables (fix #3169) (#3170)
  • Loading branch information
noirbizarre authored Sep 19, 2024
1 parent ff9e871 commit 5db006a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/3169.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensures that `/` is URL encoded in sources URL environment variables.
2 changes: 1 addition & 1 deletion src/pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def expand_env_vars(credential: str, quote: bool = False, env: Mapping[str, str]

def replace_func(match: Match) -> str:
rv = env.get(match.group(1), match.group(0))
return parse.quote(rv) if quote else rv
return parse.quote(rv, "") if quote else rv

return re.sub(r"\$\{(.+?)\}", replace_func, credential)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ def test_expand_env_vars(given, expected, monkeypatch):
("https://example.org/path?arg=1", "https://example.org/path?arg=1"),
(
"https://${FOO}@example.org/path?arg=1",
"https://hello@example.org/path?arg=1",
"https://token%3Aoidc%2F1@example.org/path?arg=1",
),
(
"https://${FOO}:${BAR}@example.org/path?arg=1",
"https://hello:wo%3Arld@example.org/path?arg=1",
"https://token%3Aoidc%2F1:p%40ssword@example.org/path?arg=1",
),
(
"https://${FOOBAR}@example.org/path?arg=1",
Expand All @@ -230,8 +230,8 @@ def test_expand_env_vars(given, expected, monkeypatch):
],
)
def test_expand_env_vars_in_auth(given, expected, monkeypatch):
monkeypatch.setenv("FOO", "hello")
monkeypatch.setenv("BAR", "wo:rld")
monkeypatch.setenv("FOO", "token:oidc/1")
monkeypatch.setenv("BAR", "p@ssword")
assert utils.expand_env_vars_in_auth(given) == expected


Expand Down

0 comments on commit 5db006a

Please sign in to comment.