Skip to content

Commit

Permalink
mkhtml: use UTF-8 for decoding git log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
landam committed Aug 27, 2022
1 parent 3aca5a4 commit 6e7ea48
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions tools/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,18 @@ def fatal(message):
)


def _get_encoding():
encoding = locale.getdefaultlocale()[1]
if not encoding:
encoding = 'UTF-8'
return encoding


def decode(bytes_):
def decode(bytes_, encoding='UTF-8'):
"""Decode bytes with default locale and return (unicode) string
No-op if parameter is not bytes (assumed unicode string).
:param bytes bytes_: the bytes to decode
:param str encoding: encoding
"""
if isinstance(bytes_, unicode):
return bytes_
if isinstance(bytes_, bytes):
enc = _get_encoding()
return bytes_.decode(enc)
return bytes_.decode(encoding)
return unicode(bytes_)


Expand Down Expand Up @@ -355,7 +348,7 @@ def read_file(name):
if PY2:
return s
else:
return decode(s)
return decode(s, encoding='ISO-8859-1')
except IOError:
return ""

Expand Down

0 comments on commit 6e7ea48

Please sign in to comment.