# HG changeset patch # User Matt Mackall # Date 2008-08-11 03:55:00 # Node ID 892806b3fc0fc431bdb3cfc665338630ca182f5a # Parent 24fd94ed1cc03b947310d9dc9764f874a87a170d util: disinfect lookup_reg strings (issue1126) lookup_reg could return Unicode strings, which would infect other strings and generate unexpected tracebacks. Spotted by Rémy Roy. Fold in silly nested function while we're at it. diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py --- a/mercurial/util_win32.py +++ b/mercurial/util_win32.py @@ -201,21 +201,17 @@ def lookup_reg(key, valname=None, scope= except ImportError: return None - def query_val(scope, key, valname): - try: - keyhandle = OpenKey(scope, key) - return QueryValueEx(keyhandle, valname)[0] - except EnvironmentError: - return None - if scope is None: scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) elif not isinstance(scope, (list, tuple)): scope = (scope,) for s in scope: - val = query_val(s, key, valname) - if val is not None: - return val + try: + val = QueryValueEx(OpenKey(scope, key), valname)[0] + # never let a Unicode string escape into the wild + return util.tolocal(val.encode('UTF-8')) + except EnvironmentError: + pass def system_rcpath_win32(): '''return default os-specific hgrc search path'''