Patchwork [6,of,6,py3] config: guard against setconfig specifying unicode values on py3

login
register
mail settings
Submitter Augie Fackler
Date March 7, 2017, 4:25 p.m.
Message ID <1bd41b5fdf2b19d4c3bf.1488903920@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/18964/
State Superseded
Headers show

Comments

Augie Fackler - March 7, 2017, 4:25 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1488570176 18000
#      Fri Mar 03 14:42:56 2017 -0500
# Node ID 1bd41b5fdf2b19d4c3bf9fc47a81fc3b85cddf79
# Parent  4801067dee2c77ff4e720c931d8b19cf32515beb
config: guard against setconfig specifying unicode values on py3

This was leading to some difficult to trace problems because the
values were set in one place, but then blew up much later in the
program. Exploding violently with an assertion seems reasonable here.

Patch

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -13,6 +13,7 @@  import os
 from .i18n import _
 from . import (
     error,
+    pycompat,
     util,
 )
 
@@ -69,6 +70,9 @@  class config(object):
     def items(self, section):
         return self._data.get(section, {}).items()
     def set(self, section, item, value, source=""):
+        if pycompat.ispy3:
+            assert not isinstance(value, str), (
+                'config values may not be unicode strings on Python 3')
         if section not in self:
             self._data[section] = util.sortdict()
         self._data[section][item] = value