diff --git a/Lib/pdb.py b/Lib/pdb.py index fc83728fb6dc94..729f1e26add1c9 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -378,11 +378,12 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, self.rcLines.extend(rcFile) except OSError: pass - try: - with open(".pdbrc", encoding='utf-8') as rcFile: - self.rcLines.extend(rcFile) - except OSError: - pass + if os.path.abspath(".pdbrc") != os.path.expanduser("~/.pdbrc"): + try: + with open(".pdbrc", encoding='utf-8') as rcFile: + self.rcLines.extend(rcFile) + except OSError: + pass self.commands = {} # associates a command list to breakpoint numbers self.commands_defining = False # True while in the process of defining diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 6b74e21ad73d1a..d16475116e1a46 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3935,6 +3935,23 @@ def test_readrc_homedir(self): f.write("invalid") self.assertEqual(pdb.Pdb().rcLines[0], "invalid") + def test_readrc_current_dir(self): + with os_helper.temp_cwd() as cwd: + rc_path = os.path.join(cwd, ".pdbrc") + with open(rc_path, "w") as f: + f.write("invalid") + self.assertEqual(pdb.Pdb().rcLines[-1], "invalid") + + def test_readrc_cwd_is_home(self): + with os_helper.EnvironmentVarGuard() as env: + env.unset("HOME") + with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"): + rc_path = os.path.join(cwd, ".pdbrc") + os.path.expanduser.return_value = rc_path + with open(rc_path, "w") as f: + f.write("invalid") + self.assertEqual(pdb.Pdb().rcLines, ["invalid"]) + def test_header(self): stdout = StringIO() header = 'Nobody expects... blah, blah, blah'