File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments