[3.13] gh-128636: Fix crash in PyREPL when os.environ is overwritten with an invalid value for macOS (GH-138089) (GH-138942)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

(cherry picked from commit 8ef7735c53)
This commit is contained in:
Łukasz Langa 2025-09-15 23:53:51 +01:00 committed by GitHub
parent d8b3a83cf2
commit 3669efb890
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 8 deletions

View file

@ -327,3 +327,12 @@ def test_getheightwidth_with_invalid_environ(self, _os_write):
self.assertIsInstance(console.getheightwidth(), tuple)
os.environ = []
self.assertIsInstance(console.getheightwidth(), tuple)
@unittest.skipUnless(sys.platform == "darwin", "requires macOS")
def test_restore_with_invalid_environ_on_macos(self, _os_write):
# gh-128636 for macOS
console = UnixConsole(term="xterm")
with os_helper.EnvironmentVarGuard():
os.environ = []
console.prepare() # needed to call restore()
console.restore() # this should succeed