changeset 34129:902219a99901

debuginstall: use codecs.lookup() to detect invalid encoding encoding.fromlocal() never tries to decode an ascii string since 853574db5b12, and there's no universal non-ascii string which can be decoded as any valid character set.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 07 Sep 2017 22:27:23 +0900
parents 82bd4c5a81e5
children ada8a19672ab
files mercurial/debugcommands.py tests/test-install.t
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Sun Sep 10 23:37:14 2017 +0900
+++ b/mercurial/debugcommands.py	Thu Sep 07 22:27:23 2017 +0900
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+import codecs
 import collections
 import difflib
 import errno
@@ -997,8 +998,8 @@
     fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding)
     err = None
     try:
-        encoding.fromlocal("test")
-    except error.Abort as inst:
+        codecs.lookup(pycompat.sysstr(encoding.encoding))
+    except LookupError as inst:
         err = inst
         problems += 1
     fm.condwrite(err, 'encodingerror', _(" %s\n"
--- a/tests/test-install.t	Sun Sep 10 23:37:14 2017 +0900
+++ b/tests/test-install.t	Thu Sep 07 22:27:23 2017 +0900
@@ -76,6 +76,11 @@
   1 problems detected, please check your install!
   [1]
 
+hg debuginstall with invalid encoding
+  $ HGENCODING=invalidenc hg debuginstall | grep encoding
+  checking encoding (invalidenc)...
+   unknown encoding: invalidenc
+
 path variables are expanded (~ is the same as $TESTTMP)
   $ mkdir tools
   $ touch tools/testeditor.exe