Skip to content

Commit 48ef0ec

Browse files
gsliepenagx
authored andcommitted
changelog: try iso8859-1 when utf-8 fails
Fall back to iso8859-1 when opening the changelog. Helps when importing old versions. Closes: #900841 Signed-off-by: Guido Günther <[email protected]>
1 parent 6c30ac9 commit 48ef0ec

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

gbp/deb/changelog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ def _parse(self):
128128
self._cp = cp
129129

130130
def _read(self):
131-
with open(self.filename, encoding='utf-8') as f:
132-
self._contents = f.read()
131+
try:
132+
with open(self.filename, encoding='utf-8') as f:
133+
self._contents = f.read()
134+
except UnicodeDecodeError:
135+
with open(self.filename, encoding='iso-8859-1') as f:
136+
self._contents = f.read()
133137

134138
def __getitem__(self, item):
135139
return self._cp[item]

gbp/git/vfs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def __init__(self, content, binary=False):
3333
if binary:
3434
self._data = io.BytesIO(content)
3535
else:
36-
self._data = io.StringIO(content.decode())
36+
try:
37+
self._data = io.StringIO(content.decode())
38+
except UnicodeDecodeError:
39+
self._data = io.StringIO(content.decode("iso-8859-1"))
3740

3841
def readline(self):
3942
return self._data.readline()

0 commit comments

Comments
 (0)