mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-119310: Fix encoding when reading old history file (#121779)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
eca3fe40c2
commit
e95984826e
4 changed files with 59 additions and 6 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue