diff options
author | aorcajo <589252+aorcajo@users.noreply.github.com> | 2024-09-06 13:40:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 13:40:29 (GMT) |
commit | e95984826eb3cdb3a3baedb2ccea35e11e9f8161 (patch) | |
tree | e0da0f6859619058f26069c7c9f39dc13249e022 /Lib/_pyrepl | |
parent | eca3fe40c251d51964172dd4e6e9c7d0d85d7d4a (diff) | |
download | cpython-e95984826eb3cdb3a3baedb2ccea35e11e9f8161.zip cpython-e95984826eb3cdb3a3baedb2ccea35e11e9f8161.tar.gz cpython-e95984826eb3cdb3a3baedb2ccea35e11e9f8161.tar.bz2 |
gh-119310: Fix encoding when reading old history file (#121779)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/_pyrepl')
-rw-r--r-- | Lib/_pyrepl/readline.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py index 4929dd3..5e1d308 100644 --- a/Lib/_pyrepl/readline.py +++ b/Lib/_pyrepl/readline.py @@ -427,12 +427,16 @@ class _ReadlineWrapper: history = self.get_reader().history with open(os.path.expanduser(filename), 'rb') as f: - lines = [line.decode('utf-8', errors='replace') for line in f.read().split(b'\n')] + is_editline = f.readline().startswith(b"_HiStOrY_V2_") + if is_editline: + encoding = "unicode-escape" + else: + f.seek(0) + encoding = "utf-8" + + lines = [line.decode(encoding, errors='replace') for line in f.read().split(b'\n')] buffer = [] for line in lines: - # Ignore readline history file header - if line.startswith("_HiStOrY_V2_"): - continue if line.endswith("\r"): buffer.append(line+'\n') else: |