Skip to content

Commit efedf09

Browse files
authored
Merge pull request #11759 from pradyunsg/fix-keyring-auth
Closes #11658
2 parents 60a4598 + 17e20c7 commit efedf09

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/pip/_internal/network/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def _get_password(self, service_name: str, username: str) -> Optional[str]:
128128
)
129129
if res.returncode:
130130
return None
131-
return res.stdout.decode("utf-8").strip("\n")
131+
return res.stdout.decode("utf-8").strip(os.linesep)
132132

133133
def _set_password(self, service_name: str, username: str, password: str) -> None:
134134
"""Mirror the implementation of keyring.set_password using cli"""
135135
if self.keyring is None:
136136
return None
137137

138138
cmd = [self.keyring, "set", service_name, username]
139-
input_ = password.encode("utf-8") + b"\n"
139+
input_ = (password + os.linesep).encode("utf-8")
140140
env = os.environ.copy()
141141
env["PYTHONIOENCODING"] = "utf-8"
142142
res = subprocess.run(cmd, input=input_, env=env)

tests/unit/test_network_auth.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import functools
2+
import os
23
import sys
34
from typing import Any, Dict, Iterable, List, Optional, Tuple
45

@@ -360,7 +361,7 @@ def __call__(
360361
self.returncode = 1
361362
else:
362363
# Passwords are returned encoded with a newline appended
363-
self.stdout = password.encode("utf-8") + b"\n"
364+
self.stdout = (password + os.linesep).encode("utf-8")
364365

365366
if cmd[1] == "set":
366367
assert stdin is None
@@ -369,7 +370,7 @@ def __call__(
369370
assert input is not None
370371

371372
# Input from stdin is encoded
372-
self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip("\n"))
373+
self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip(os.linesep))
373374

374375
return self
375376

0 commit comments

Comments
 (0)