gh-128636: Fix crash in PyREPL when os.environ is overwritten with an invalid value (#128653)

This commit is contained in:
Tomas R. 2025-01-22 17:15:23 +01:00 committed by GitHub
parent 2ed5ee9a50
commit ba9a4b6215
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View file

@ -1,7 +1,9 @@
import itertools
import os
import sys
import unittest
from functools import partial
from test.support import os_helper
from unittest import TestCase
from unittest.mock import MagicMock, call, patch, ANY
@ -312,3 +314,14 @@ class TestConsole(TestCase):
)
console.restore()
con.restore()
def test_getheightwidth_with_invalid_environ(self, _os_write):
# gh-128636
console = UnixConsole()
with os_helper.EnvironmentVarGuard() as env:
env["LINES"] = ""
self.assertIsInstance(console.getheightwidth(), tuple)
env["COLUMNS"] = ""
self.assertIsInstance(console.getheightwidth(), tuple)
os.environ = []
self.assertIsInstance(console.getheightwidth(), tuple)