Skip to content

Commit ae8ba6e

Browse files
Yahya FarhadiLarsAsplund
authored andcommitted
fix(sim): address review - drop utf-8-sig and cp1252, use backslashreplace fallback
1 parent 42f8358 commit ae8ba6e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

vunit/sim_if/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,20 @@ def _decode(data: bytes) -> str:
368368
which can raise UnicodeDecodeError if decoded as strict UTF-8.
369369
"""
370370

371-
encodings_to_try = (
371+
# Deduplicate via dict.fromkeys to avoid trying utf-8 twice
372+
# when locale.getpreferredencoding() returns "UTF-8".
373+
encodings_to_try = dict.fromkeys([
372374
"utf-8",
373-
"utf-8-sig",
374-
locale.getpreferredencoding(False) or "utf-8",
375-
"cp1252",
376-
)
375+
locale.getpreferredencoding(False),
376+
])
377377

378378
for encoding in encodings_to_try:
379379
try:
380380
return data.decode(encoding)
381381
except UnicodeDecodeError:
382382
continue
383383

384-
return data.decode("utf-8", errors="replace")
384+
return data.decode("utf-8", errors="backslashreplace")
385385

386386
try:
387387
output = subprocess.check_output( # pylint: disable=unexpected-keyword-arg

0 commit comments

Comments
 (0)